tag:blogger.com,1999:blog-64205871604240198442024-03-13T19:31:00.695-07:00Igor Alekseev's programming blogIgor Alekseev's blogAnonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.comBlogger45125tag:blogger.com,1999:blog-6420587160424019844.post-7297102276265849292016-02-12T05:21:00.000-08:002016-02-13T01:38:49.681-08:00Using Google Translate & Microsoft Translator services in Scala in a non-blocking way<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
I am happy to announce the creation of an idiomatic Scala library named <a href="https://github.com/SmartElk/fluent-translator" target="_blank">fluent-translator</a> for working with Microsoft, Google etc. language translation services. This Scala library aims to provide an universal fancy DSL for working with all popular language translators around. And do it in a reactive non-blocking way. Currently Microsoft Translator and Google Translate services are supported. <br />
<br />
I'll put few sexy usage examples below:</div>
<pre style="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;"> Microsoft give me a translation of "Comment vas-tu?" to "en" as future //Future[String]
Microsoft give me many translations of "Doing well by doing good" from "en" to "ru" as future //Future[GetTranslationsResponse]
Microsoft speak "I'm doing well enough now" in "en" withAudioContentType `audio/mp3` as future //Future[SpeakResponse]
Google give me a translation of "Comment vas-tu?" to "en" as future //Future[String]
Google give me a translation of "What a lovely weather today!" from "en" to "fr" withContentType `text/html` as future //Future[String]
</code></pre>
<br />
You are welcome to use/contribute it on <a href="https://github.com/SmartElk/fluent-translator" target="_blank">GitHub</a>. And I'll be glad to hear your suggestions as well. </div>
Anonymoushttp://www.blogger.com/profile/09570897100406464953noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-5203637446296299412015-04-24T02:53:00.000-07:002015-04-24T02:53:43.952-07:00Comparing covariance/contravariance rules in C#, Java and Scala<div dir="ltr" style="text-align: left;" trbidi="on">
Different programming languages support variance (covariance/contravariance) in different ways. My goal is to compare all supported types of variance in C#, Java and Scala, and to reason about why some architectural decisions have been made by language designers.<br />
<div>
<br /></div>
<div>
<table style="background-color: white; border-collapse: collapse; border: 1px solid rgb(225, 225, 224); color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;"><tbody style="border: 0px; margin: 0px; padding: 0px;">
<tr style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 0px;"><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;"> </td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;"><div dir="ltr">
<strong style="border: 0px; margin: 0px; padding: 0px;">C#</strong></div>
</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;"><div dir="ltr">
<strong style="border: 0px; margin: 0px; padding: 0px;">Java</strong></div>
</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;"><div dir="ltr">
<strong style="border: 0px; margin: 0px; padding: 0px;">Scala</strong></div>
</td></tr>
<tr style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 0px;"><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">Arrays covariance</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">+<div dir="ltr">
(unsafe at runtime)</div>
</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">+<div dir="ltr">
(unsafe at runtime)</div>
</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">_<div dir="ltr">
<br /></div>
<div dir="ltr">
(arrays are invariant by design)</div>
<div dir="ltr">
Though, there is support for Java's "covariant" arrays, of course.</div>
</td></tr>
<tr style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 0px;"><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">Arrays contravariance</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">_</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">_</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">_</td></tr>
<tr style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 0px;"><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">Generics variance<div dir="ltr">
(covariance/contravariance)</div>
</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">+<div dir="ltr">
<br /></div>
<div dir="ltr">
Defined by a generic type creator (definition-site).</div>
<div dir="ltr">
(Restricted to generic interfaces and generic delegates)</div>
</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">+<div dir="ltr">
<br /></div>
<div dir="ltr">
Defined by clients of generic type using wildcards (use-site).</div>
</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">+<div dir="ltr">
<br /></div>
<div dir="ltr">
Defined by a generic type creator (definition-site).</div>
<div dir="ltr">
Also, there are existential types that cover Java's wildcards functionality.</div>
</td></tr>
<tr style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 0px;"><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">Overriding: return type covariance</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">_</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">+</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">+</td></tr>
<tr style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 0px;"><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">Overriding: parameter type contravariance</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">_</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;">_</td><td style="border: 1px solid rgb(225, 225, 224); margin: 0px; padding: 5px; vertical-align: top;"><a href="http://www.codeproject.com/Articles/899319/Comparing-covariance-contravariance-rules#parameterTypeContravarianceScala">_</a></td></tr>
</tbody></table>
<br /><div dir="ltr" style="background-color: white; border: 0px; color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; margin: 0px; padding: 0px;">
</div>
</div>
<div>
<a href="http://www.codeproject.com/Articles/899319/Comparing-covariance-contravariance-rules" target="_blank">Continue reading on CodeProject-></a></div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-85408150914608853702014-11-09T05:13:00.000-08:002015-03-07T09:51:12.357-08:00Subprojects in PlayFramework 2.3 (Scala): overcoming difficulties<div dir="ltr" style="text-align: left;" trbidi="on">
After struggling a bit to configure a Play 2.3 application (Scala) to work with subprojects (including another Play application) I've decided to create a simple example on <a href="https://github.com/ialekseev/PlayFramework2.3_Scala-with-subprojects-example" target="_blank">GitHub</a>.<br />
<br />
Things to pay attention to:<br />
<ul style="text-align: left;">
<li><b>Build.sbt</b> in the Root project to configure modules</li>
<li>Root's <b>conf/routes</b> to attach Play subproject's routes to the routing system</li>
<li>Play subproject's routes in <b>modules/{subproject-name}/conf/{subproject-name}.routes</b></li>
<li>Play subproject's <b>build.sbt </b>without unnecessary information</li>
<li>Play subproject's controllers and views reside in additional subpackages {subproject-name}</li>
<li>Explicitly added <b>Assets</b> controller in Play subproject</li>
<li>How assests are referenced in Play subproject's <b>main.scala.html</b></li>
</ul>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-7546172208450963802014-08-17T08:50:00.000-07:002015-03-07T09:57:57.993-08:00Introducing Antler Framework to the CodeProject community(Part II)<div dir="ltr" style="text-align: left;" trbidi="on">
Welcome to read another article about Antler framework on the <a href="http://www.codeproject.com/Articles/801423/Antler-Abstraction-over-ORM-that-you-like-to-use" target="_blank">CodeProject </a>in which I dived into details of implementing configurable Unit-of-work and ORM adapters.</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-6092938652852517732014-05-31T02:13:00.000-07:002015-03-07T10:01:31.847-08:00Introducing Antler Framework to the CodeProject community<div dir="ltr" style="text-align: left;" trbidi="on">
I've just posted an article introducing our open-source framework Antler to the CodeProject community.<br />
<br />
The concepts explained in the article:<br />
<br />
<ul style="text-align: left;">
<li>Antler framework is an abstraction over ORMs</li>
<li>Antler framework is an abstraction over IoC containers</li>
<li>Antler framework improves testability of applications that use it</li>
<li>Antler framework has pluggable structure</li>
</ul>
<br />
If you are interested you are welcomed to dive into the details on the <a href="http://www.codeproject.com/Articles/774968/Antler-Abstraction-over-ORM-that-you-like-to-use-i" target="_blank">CodeProject</a>.</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-42435065622765217472014-03-31T12:06:00.001-07:002014-03-31T12:15:16.547-07:00Antler Framework: TeamCity build server for our open source project<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
We are pleased to announce the launch of <i>TeamCity</i> build server for the <a href="https://github.com/SmartElk/Antler" target="_blank">Antler Framework</a> for public viewing.<br />
<br />
It is available <a href="http://smartelk.com:8111/guestLogin.html?guest=1" target="_blank">here</a>.<br />
<br />
<span style="background-color: white;"><span style="font-family: inherit;"><span style="font-size: x-small;">Antler Framework is a pluggable framework for .NET to work with popular ORMs(NHibernate, EntityFramework Code First) using the same syntax. </span><span style="font-size: x-small;">GitHub: </span><a href="https://github.com/SmartElk/Antler" style="font-size: small;" target="_blank">https://github.com/SmartElk/Antler</a><span style="font-size: x-small;">.</span></span></span><br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-63128113715103992242014-02-27T22:11:00.000-08:002015-03-07T10:04:09.166-08:00Antler Framework: Releasing 2.0 Version<div dir="ltr" style="text-align: left;" trbidi="on">
<i>Antler</i> is a pluggable framework for damn-easy good-style working with different ORMs using the same syntax.<br />
<br />
"Pluggable" means that you can easily switch, say, between <i>NHibernate</i> and <i>EntityFramework Code First</i> using one line of code. Also you can easily switch your IoC container: currently we have <i>Castle Windsor</i> and <i>StructureMap</i> adapters.<br />
<br />
Configuration example (using <i>EntityFramework</i> ORM + <i>Castle Windsor</i> container):<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> var configurator = new AntlerConfigurator();
configurator.UseWindsorContainer().UseStorage(EntityFrameworkStorage.Use.WithConnectionString(connectionString).WithMappings(assemblyWithMappings));
</code></pre>
<br />
<i>Antler Framework</i> has strong architectural background out of the box: you can easily build your layered design using build-in support for <i>UnitOfWork</i>, <i>Repository </i>etc patterns.<br />
<br />
If you are interested you are welcomed on GitHub:<br />
<a href="https://github.com/SmartElk/Antler" target="_blank">https://github.com/SmartElk/Antler</a></div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-92119544918010816042014-01-26T08:37:00.000-08:002014-01-26T08:37:55.621-08:00Powershell: Deploying Windows Service remotely<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;">As a big adherent of <i>Continuous Integration</i> practice I often need to deploy a Windows Service on an another computer remotely "by click".</span><br />
<span style="font-family: inherit;"><br />
Mostly, this task is performed from our <i>TeamCity</i> Build Server and consists of the following steps:</span><br />
<ul style="text-align: left;">
<li><span style="font-family: inherit;">Stopping remote Windows Service</span></li>
<li><span style="font-family: inherit;">Backuping it's files</span></li>
<li><span style="font-family: inherit;">Copying new files into the remote folder where the service is</span></li>
<li><span style="font-family: inherit;">Starting remote Windows Service</span></li>
</ul>
<span style="font-family: inherit;">
It's very easy to accomplish these steps using <i>Powershell</i>:</span><br />
<ul style="text-align: left;">
<li><span style="font-family: inherit;"><i>Get-WmiObject</i> cmdlet is used for managing Windows Service </span>remotely</li>
<li><span style="font-family: inherit;"><i>Robocopy </i>tool is used for "smart" copying files into remote shared folder</span></li>
</ul>
<span style="font-family: inherit;">
If you are interested you can find the simplified script example on <i>GitHub</i>: </span><br />
<div>
<a href="https://github.com/ialekseev/DeployRemoteServiceExample" target="_blank"><span style="font-family: inherit;">https://github.com/ialekseev/DeployRemoteServiceExample</span></a></div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-58468697592312378082013-12-30T02:18:00.004-08:002013-12-30T02:18:34.235-08:00NuGet: Publishing different packages from the same solution<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr">
Let's say we need to generate different NuGet packages from our solution: core package and some specific adapter packages(e.g. Windsor container adapter package, EntityFramework + SQL CE adapter package).</div>
<div dir="ltr">
<span style="background-color: rgba(255, 255, 255, 0);"><br /></span></div>
<div dir="ltr">
<span style="background-color: rgba(255, 255, 255, 0);">This raises some interesting questions:</span></div>
<div dir="ltr">
</div>
<ul style="text-align: left;">
<li>How not to get confused with different versions when republishing packages?</li>
<li>How not to forget to republish some package after you updated one of underlying projects?</li>
<li>How to remember that you need to update some package(because you made some changes in underlying projects) and you don't need to update other packages(because you didn't make any changes to that projects)?</li>
</ul>
<br />
<div dir="ltr">
So, how the hell to keep this process simple and straightforward?</div>
<div dir="ltr">
<br /></div>
<div dir="ltr">
My answer is to republish every NuGet package from solution <b>at once</b>.<br />
I have just one script file to run. When I run this file the following is happened:</div>
<ul style="text-align: left;">
<li>All projects from my solution are built in Release mode;</li>
<li>Tests are run;</li>
<li>All NuGet packages are created;</li>
<li>All NuGet packages are published with the <b>same</b> specified version;</li>
</ul>
<br />
<div dir="ltr">
When I need to update <b>any</b> package from my solution I just run this script. I do not need to remember which projects from my solution I updated and which package I need to republish(core or some adapter). All I need is to run one script without any potential problems to upload broken package to NuGet repository.</div>
<div dir="ltr">
<br /></div>
<div dir="ltr">
Now I am planning to include republishing step in our Continuous Integration Server(TeamCity) using almost the same script.</div>
<div dir="ltr">
<br /></div>
<div dir="ltr">
See example of the build script in our Antler project: <a href="http://www.blogger.com/"></a><br />
<a href="https://github.com/SmartElk/Antler/tree/master/build" target="_blank">https://github.com/SmartElk/Antler/tree/master/build</a></div>
<div dir="ltr">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-90613442892136856442013-11-30T06:43:00.001-08:002014-03-31T11:16:23.421-07:00Antler Framework: use the same syntax to work with different databases and different ORMs.<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
I am starting to contribute to <i><a href="https://github.com/SmartElk/Antler" target="_blank">Antler</a></i> project which i believe may be useful for many .Net developers as well.<br />
<br />
<i>Antler</i> is a simple framework for super-easy working with different databases(SQL CE, Sqlite, SqlExpress, SqlServer, Oracle etc) and different ORMs(NHibernate, EntityFramework Code First) using the same syntax.<br />
<br />
Project is at an early stage, but we have a clear understanding of the requirements.<br />
<br />
So, what are the requirements?<br />
<div>
<ul style="text-align: left;">
<li>Support for multiple storages at the same time.</li>
<li>Use common syntax to work with them, so you can easily substitute one storage with another.</li>
<li>Have strong architectural base including <i>UnitOfWork/DataSession/Repository</i> <i>etc</i>. notions.</li>
<li>Be fully pluggable. For example, it should be damn easy to choose which storage or IoC container to use.</li>
<li>Good coverage by Unit/Integration tests. Most of the integration tests should pass for any combination of Database/ORM.</li>
</ul>
<u><br /></u>
<u>Configuration example</u><br />
<br /></div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> var configurator = new AntlerConfigurator();
configurator.UseWindsorContainer().UseStorage(NHibernatePlusSqlite.Use.WithMappings(Assembly.GetExecutingAssembly()));
</code></pre>
<div>
<br /></div>
<div>
<u>Usage example</u><br />
<i><br /></i>
<i>Adding teams to database:</i><br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> UnitOfWork.Do(uow =>
{
uow.Repo<Team>().Insert(new Team() {Name = "Super", BusinessGroup = "Great"});
uow.Repo<Team>().Insert(new Team() {Name = "Good", BusinessGroup = "Great"});
uow.Repo<Team>().Insert(new Team() {Name = "Bad", BusinessGroup = "BadBg"});
});
</code></pre>
<br />
<i>Querying teams from database:</i><br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> var found = UnitOfWork.Do(uow => uow.Repo<Team>().AsQueryable().Where(t => t.BusinessGroup == "Great").OrderBy(t => t.Name).ToArray());
</code></pre>
<br />
Project is available on GitHub: <a href="https://github.com/SmartElk/Antler" target="_blank">https://github.com/SmartElk/Antler</a>.<br />
Everyone is welcome!<br />
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-42036938362050584742013-10-12T05:50:00.000-07:002013-10-14T11:24:55.309-07:00Integration testing approaches: Should we use in-memory database?<div dir="ltr" style="text-align: left;" trbidi="on">
Integration testing is a form of testing that verifies that components of our application properly work together & with external resources(database, disk-drive etc).<br />
<br />
Let's say we have application that uses database in some way. How can we cover components that use database by Integration tests?<br />
<br />
The most important principle of testing is <i>Isolation</i>:<br />
<br />
<div style="text-align: center;">
<span style="background-color: yellow;">Tests should be isolated in the data creating and quering from other tests.</span></div>
<br />
So, each good Integration test that uses database should consists of the following steps:<br />
<ul style="text-align: left;">
<li>Cleaning database </li>
<li>Inserting testing data </li>
<li>Calling component being tested </li>
<li>Checking result / database state </li>
</ul>
<div>
<br /></div>
There are 3 popular ways to write Integration Tests:<br />
<ol style="text-align: left;">
<li>Use the same development database for Integration tests </li>
<li>Generate empty database before each test </li>
<li>Use some in-memory database </li>
</ol>
<b>1</b>. The first choice is to use the same development database for testing. This choice is the worst one, because we can't populate development database by testing data without breaking <i>Isolation</i> principle. <br />
<br />
<div>
So, it's read-only mode testing. We can test some read-only requests to database, but even then, we are unable to make assertions well, because this data is fragile(we can make changes in our development database at any time and tests will be broken).<br />
<br />
<b>2</b>. The second choice is to generate empty database with testing data before each test. <br />
It's good practice to have testing environment that resembles real production environment as close as possible. So, in this case we use the same database-engine for testing as production's one, which makes possible to catch some database-specific problems early.<br />
<br />
Disadvantage of this approach is that Integration tests can be pretty slow.<br />
<br />
<b>3</b>. The third choice is a to use in-memory database.<br />
If for some reasons we can't use the second choice then we can use in-memory database for testing. It's the compromise choice, because we can ensure <i>Isolation</i> of our tests + high speed of execution, but we sacrifice the closeness to the real environment.<br />
<br />
<i>Sqlite</i> is a great example of such database.<br />
<br />
For example, if we use <i>NHibernate</i> it's very easy to inject <i>Sqlite </i>database(instead of our real one) in our tests. This database will be based on the same <i>NHibernate </i>mappings and will use the same database-logic.<br />
<br />
<span style="background-color: yellow;">If you are interested in this approach, you can find example project of using <i>NHibernate </i>+ <i>Sqlite </i>for testing on <a href="https://github.com/ialekseev/SqliteExample" target="_blank">GitHub</a>.</span><br />
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com2tag:blogger.com,1999:blog-6420587160424019844.post-48173154681887231272013-09-01T02:18:00.000-07:002013-09-01T02:48:37.599-07:00JasmineJs integration with ReSharper & TeamCity<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<i>JasmineJs</i> is a great framework for testing JavaScript code.<br />
<div>
<br /></div>
<div>
We'll discuss here how to integrate it with other amazing products: <i>ReSharper 7</i> & <i>TeamCity</i>.</div>
<div>
<br /></div>
<div>
<h3 style="text-align: left;">
Download</h3>
<br />
You can download standalone example <a href="https://github.com/ialekseev/TeamCityJasmine" target="_blank">here</a>(with additional files to run tests from <i>ReSharper</i> & <i>TeamCity</i>).<br />
<br />
This package contains two folders: <span style="color: #38761d;">SpecRunner</span> and <span style="color: #38761d;">YourWebSite</span>. We’ll need them later.<br />
<div>
<br /></div>
<h3 style="text-align: left;">
JasmineJs + ReSharper 7 = Friends</h3>
<br />
To run client-side tests without dependency on your browser we can use <i>PhantomJs</i> WebKit.<br />
<br />
<div>
Put files from downloaded <span style="color: #38761d;">SpecRunner</span> folder somewhere in your solution.<br />
<br />
For example, in my solution these files are located in <i>MyProject/Testing/Client/</i> folder.<br />
<br />
Now we can configure <i>ReSharper</i> to use <i>PhantomJs</i>:</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuMVod2YHHgyc3xtXWk5J7QJZEAvKXpPrgSD0iYdPeQwO2yXiI20LtiKUxM9EQq-OGetwvGSTuJhzk6bbOi_i6d9y9bqLsKWyTfdlHafs7L1N_7uAXzEhAaoho8ylYp0qyn9dCdxxBzvs/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuMVod2YHHgyc3xtXWk5J7QJZEAvKXpPrgSD0iYdPeQwO2yXiI20LtiKUxM9EQq-OGetwvGSTuJhzk6bbOi_i6d9y9bqLsKWyTfdlHafs7L1N_7uAXzEhAaoho8ylYp0qyn9dCdxxBzvs/s1600/1.png" height="458" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
Now we can create JS-files with tests, and run them directly from <i>Visual Studio</i>(thanks to <i>ReSharper</i>) without running our browser(thanks to <i>PhantomJs</i>):<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4ox56SZVqpeZxBsMZbIyCUbjb45HGfmtDgAt69qXWA418in_JbuHkBABcSsOZ_vrPiAH1XKVlerOaDRsa13P4tvcxWBCDr-5HkO8lr4kIyR7ivo_XfHGpkUO7Fz4hCUqqjbxe27sT9uY/s1600/2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4ox56SZVqpeZxBsMZbIyCUbjb45HGfmtDgAt69qXWA418in_JbuHkBABcSsOZ_vrPiAH1XKVlerOaDRsa13P4tvcxWBCDr-5HkO8lr4kIyR7ivo_XfHGpkUO7Fz4hCUqqjbxe27sT9uY/s1600/2.PNG" height="323" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-size: 11.0pt; mso-ansi-language: EN-US;"><br /></span></div>
You need to include necessary scripts(scripts to be tested + their dependencies) using <i>reference</i> syntax.<br />
<u>However, note that we don’t need to include <i>JasmineJs</i> scripts, because <i>ReSharper</i> has it’s own inside.</u><br />
<h3 style="text-align: left;">
</h3>
<h3 style="text-align: left;">
<br /></h3>
<h3 style="text-align: left;">
JasmineJs + TeamCity = Friends</h3>
<h4 style="text-align: left;">
</h4>
<h4 style="text-align: left;">
<br /></h4>
<h4 style="text-align: left;">
Preparing project for running JS-tests from TeamCity </h4>
<br />
Put downloaded <span style="color: #38761d;">YourWebSite/lib/</span> folder in <i>Scripts/Jasmine/</i> folder of your Web project.<br />
<br />
Put downloaded <span style="color: #38761d;">YourWebSite/SpecRunner.htm</span> file in the <i>root</i> of your Web project. <br />
<br />
For example:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieZs070Y2DatqmRBBAkpp2qxpS5pMMEubfclAttiJPAzv6oCt3WKZSD0JTba_onmIwFIsOK7SYyUxb0C1CB9ZJKUQD6KrHr8ZyBfA3pRDg6muEi6oq1enfyeQ_S2fokulnHhaLwWNdZcM/s1600/3.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieZs070Y2DatqmRBBAkpp2qxpS5pMMEubfclAttiJPAzv6oCt3WKZSD0JTba_onmIwFIsOK7SYyUxb0C1CB9ZJKUQD6KrHr8ZyBfA3pRDg6muEi6oq1enfyeQ_S2fokulnHhaLwWNdZcM/s1600/3.PNG" height="400" width="161" /></a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
Then you need to configure <span style="color: #38761d;">SpecRunner.htm</span> to include all necessary scripts:<br />
<ul style="text-align: left;">
<li><i>JasmineJs</i> scripts(<i>ReSharper</i> doesn’t need them, but <i>TeamCity </i>does); </li>
<li>Source files to be tested + their dependencies; </li>
<li>Spec files with tests; </li>
<li><i>jasmine.teamcity_reporter.js </i></li>
</ul>
Note, that we include <i>jasmine.teamcity_reporter.js</i> that is needed for integration with <i>TeamCity</i>.<br />
<br />
Example of SpecRunner.htm:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZdrEthyuveJPLrorwDNAltFGeHCoUD4hyJ_BhOHHGLzX3jfVGim-gecQrn-x26nYTLpawqmUWRYm8d4Ex7_yNd-bOhYiRBrYUxChhWCe7lwdP5HIJSbnQKMWhor6Ih8OOWUQWfXOl_rM/s1600/4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZdrEthyuveJPLrorwDNAltFGeHCoUD4hyJ_BhOHHGLzX3jfVGim-gecQrn-x26nYTLpawqmUWRYm8d4Ex7_yNd-bOhYiRBrYUxChhWCe7lwdP5HIJSbnQKMWhor6Ih8OOWUQWfXOl_rM/s1600/4.PNG" height="640" width="566" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h4 style="text-align: left;">
Configuring TeamCity for running JS-tests from our project</h4>
<br />
We need to create additional Build Step in <i>TeamCity</i>:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2Gm5Ea08BTrVbh-YvB9f7iX8TA1WZkSTB8hW2tAToi083rjjXw4HznxywN-gkn7unGNAKuOs3fTefNyEXfMVlxD6CH85caim0lmlvU5iCUMR2ZqbqjKgeUaVoeKfWuCtqhmI47RdtjHg/s1600/5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2Gm5Ea08BTrVbh-YvB9f7iX8TA1WZkSTB8hW2tAToi083rjjXw4HznxywN-gkn7unGNAKuOs3fTefNyEXfMVlxD6CH85caim0lmlvU5iCUMR2ZqbqjKgeUaVoeKfWuCtqhmI47RdtjHg/s1600/5.PNG" height="268" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVT69fVll1nFlRNzffY700yWxge97_PJOTNB3uYWLwp6hXsaqg9OjVIfw_JgBtt6NXhmjGkGeboLos-2PlVFiY1kf9HfLuFG9fmJS6S_fgPcqYwHOgEDs8x9wES6HTGJwoHYOEG7Qz7RI/s1600/6.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVT69fVll1nFlRNzffY700yWxge97_PJOTNB3uYWLwp6hXsaqg9OjVIfw_JgBtt6NXhmjGkGeboLos-2PlVFiY1kf9HfLuFG9fmJS6S_fgPcqYwHOgEDs8x9wES6HTGJwoHYOEG7Qz7RI/s1600/6.PNG" height="300" width="640" /></a></div>
Note, that we specify <i>Working directory</i> as <i>Testing/Client/</i> folder of our solution(where we put downloaded files from <span style="color: #38761d;">SpecRunner</span> folder).</div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com2tag:blogger.com,1999:blog-6420587160424019844.post-40605463813225977592013-08-11T07:23:00.002-07:002013-08-11T07:28:06.533-07:00Creating and Installing Windows Services with TopShelf<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" trbidi="on">
<br />
<a href="http://www.nuget.org/packages/TopShelf" rel="nofollow" target="_blank">TopShelf </a> is a library for .NET that makes it very easy to create and install a Windows service.<br />
<br />
For example, all necessary code for creating Windows Service might look like:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> static void Main()
{
HostFactory.Run(x =>
{
x.UseLog4Net("log4net.config");
x.Service(s =>
{
s.ConstructUsing(name => new MyService());
s.WhenStarted(tc => tc.OnStart());
s.WhenStopped(tc => tc.OnStop());
});
x.SetDescription("My Service is Great!");
x.SetDisplayName("My Service");
x.SetServiceName("MyService");
x.RunAsLocalSystem();
});
}
</code></pre>
<br />
<i>MyService</i> is a class with two public methods(<i>OnStart</i> and <i>OnStop</i>). <i>OnStart</i> contains code to preform in service. <i>OnStop</i> may do some cleanup.<br />
<br />
The best benefit that comes with <i>TopShelf</i> is that service is started as Console application during development(running, debugging etc).<br />
But if you want to install service as real Windows Service, you just need to run you <i>exe</i> file with special parameter:</div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> MyService.exe install
</code></pre>
<span style="background-color: white; line-height: 13pt;"><br /></span>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-56305023507176956952013-07-27T05:56:00.000-07:002013-07-27T05:56:34.076-07:00Using Oracle in a standalone .NET application<div dir="ltr" style="text-align: left;" trbidi="on">
Our goal is to set up standalone .NET application without dependency on installed Oracle client in our system. In other words, our application should contain all necessary dll's in the <i>bin</i> folder of our project .<br /><br />We need following dll's from Oracle client :<br /><ul style="text-align: left;">
<li>oci.dll</li>
<li>OraOps11w.dll</li>
<li>oraocci11.dll</li>
<li>orannzsbb11.dll</li>
<li>oraociei11.dll</li>
<li>Oracle.DataAccess.dll</li>
</ul>
You can get them from installed version of your Oracle client. In my case it was 11.2 version of Oracle client.<br />You can put this assemblies in some folder in your solution, let's say this folder is named "Components".<br /><div>
Now you can refer <i>Oracle.DataAccess</i> in your solution projects whenever you need. So, <i>Oracle.DataAccess</i> will get to the <i>bin</i> folder of your project when you'll build it.<br /><br />But we need other Oracle libs to be in the <i>bin</i> folder too! How to force this to happen?<br /><br />You can achieve this using <i>Pre-Build Events</i> of your project. Go to <i>Properties</i> of your project, then select the <i>Build Events tab</i> and paste the following lines in <i>Pre-build event box</i>:<br /><br />copy $(ProjectDir)\..\..\Components\oci.dll $(TargetDir)<br />copy $(ProjectDir)\..\..\Components\OraOps11w.dll $(TargetDir)<br />copy $(ProjectDir)\..\..\Components\oraocci11.dll $(TargetDir)<br />copy $(ProjectDir)\..\..\Components\orannzsbb11.dll $(TargetDir)<br />copy $(ProjectDir)\..\..\Components\oraociei11.dll $(TargetDir)<br /><br />Maybe, you'll need to <u>correct paths for your case</u>, but you should get the idea: these Oracle libraries will be copied into the <i>bin</i> folder of your project before the each build.<br />So, after each build you will get standalone application(with all necessary Oracle client libs), that can run on any computer without the need to install Oracle on this computer.</div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-47013001349043859942013-07-03T11:53:00.000-07:002013-09-01T02:34:10.927-07:00Using Rhino Mocks after FakeItEasy experience<div dir="ltr" style="text-align: left;" trbidi="on">
Recent years i always use <a href="https://github.com/FakeItEasy/FakeItEasy" target="_blank">FakeItEasy</a> as my favorite mock framework. And i was very happy about it.<br />
<br />
But few weeks ago i have joined team that uses <a href="http://www.hibernatingrhinos.com/oss/rhino-mocks" target="_blank">Rhino Mocks</a>. So, i've got a chance to compare them.<br />
<br />
Both frameworks provide just about the same facilities, but i found <i>FakeItEasy</i> syntax more convenient to use. Plus, there is no difference between <i>stub</i> and <i>mock</i> in <i>FakeItEasy</i>- everything is just a f<i>ake</i>! You don't need to remember which one to use. In <i>Rhino Mocks</i> i sometimes create <i>stub</i>, then later, decide to create expectations on it and then wonder: "Why my expectations are always pass?" Then i realize that i need to refactor my code to use <i>mock</i> instead of <i>stub</i>. There are no such problems in <i>FakeItEasy</i>.<br />
<br />
Maybe it's a matter of habit, but my advice is to use <i>FakeItEasy</i>, it's much cooler. </div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-53173085870988336702013-05-31T08:51:00.000-07:002013-05-31T08:51:03.228-07:00Programming in Seychelles<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="border-collapse: separate; border-spacing: 0px; font-family: Tahoma; orphans: 2; text-align: -webkit-auto; widows: 2;">Just kidding... It's impossible to concentrate on serious work in Seychelles, because it's paradise without any doubt. </span><br />
<div>
<span style="border-collapse: separate; border-spacing: 0px; font-family: Tahoma; orphans: 2; text-align: -webkit-auto; widows: 2;"><br /></span></div>
<div>
<span style="border-collapse: separate; border-spacing: 0px; font-family: Tahoma; orphans: 2; text-align: -webkit-auto; widows: 2;">I had long vacation on Seychelles islands and i tell you now: i have never seen such a beautiful country before.</span></div>
<br />
<i>Anse Georgette beach(Praslin island):</i><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyx29g2Hhw7G42WAvCKAi0F44KI_hM6RKzxsc0EleUecFnxYw8wxbkKsABz3YlOIxPRSc3FOV-f_YEfrlfS4x46iyuZYjsYfhG4ym3Q2p5PNSqVMrgnUU5XO2Kx5QfzSATu4kky4VsSkl1/s1600/DSC_0637.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Anse Georgette beach(Praslin island)" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyx29g2Hhw7G42WAvCKAi0F44KI_hM6RKzxsc0EleUecFnxYw8wxbkKsABz3YlOIxPRSc3FOV-f_YEfrlfS4x46iyuZYjsYfhG4ym3Q2p5PNSqVMrgnUU5XO2Kx5QfzSATu4kky4VsSkl1/s1600/DSC_0637.JPG" height="425" title="Anse Georgette beach(Praslin island)" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<i>Giant Tortoise on Curious island:</i></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlDSFVKDrqNWED3dpvjDMReYu_jfiANXa1OGS5Pi9mOCPvnerTsRf2II79HMyye4lyuQnfM70ML794IzabGnPOJX3PuCXwCTpNsx-Q65pnsK_CWuHDJuGTXUWbFgtdoH4hVe8sUit1bb0x/s1600/DSC_1112.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Giant Tortoise on Curious island" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlDSFVKDrqNWED3dpvjDMReYu_jfiANXa1OGS5Pi9mOCPvnerTsRf2II79HMyye4lyuQnfM70ML794IzabGnPOJX3PuCXwCTpNsx-Q65pnsK_CWuHDJuGTXUWbFgtdoH4hVe8sUit1bb0x/s1600/DSC_1112.JPG" height="426" title="Giant Tortoise on Curious island" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<i></i><br />
<div>
<i>Petite Anse Kerlan beach(Praslin island):</i></div>
<i>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD6t_QCT3SA8HyBTXuBCdBw6hy5EagHFeACn0UfVYdtPWcQeuQqMXBnL3GCnDYUBW1NS8LwFR_Ruv6pRyr2QnmUjm65Qpqv2gVFpmPyR_svodZVmPUYqR18zH-y4YnXAANItiffS80dE1M/s1600/DSC_0584.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Petite Anse Kerlan beach(Praslin island)" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD6t_QCT3SA8HyBTXuBCdBw6hy5EagHFeACn0UfVYdtPWcQeuQqMXBnL3GCnDYUBW1NS8LwFR_Ruv6pRyr2QnmUjm65Qpqv2gVFpmPyR_svodZVmPUYqR18zH-y4YnXAANItiffS80dE1M/s1600/DSC_0584.JPG" height="426" title="Petite Anse Kerlan beach(Praslin island)" width="640" /></a></div>
<div>
<br /></div>
<div>
<i>Small and beautiful Coco island:</i></div>
</i><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtJDdmjc7FVwTbnree8cxc8FEVvumO87RldsR4DZmDeX0d4yfQmxl6ZekRdQs_qIvL06_Ae4aeJ36t4Mcn2wx_iOIHKuKYY9BpCI29kIZy-PFt7KPaMP_2arNpz6Do57pxZRt36FVYOAup/s1600/DSC_0614.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Small and beautiful Coco island" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtJDdmjc7FVwTbnree8cxc8FEVvumO87RldsR4DZmDeX0d4yfQmxl6ZekRdQs_qIvL06_Ae4aeJ36t4Mcn2wx_iOIHKuKYY9BpCI29kIZy-PFt7KPaMP_2arNpz6Do57pxZRt36FVYOAup/s1600/DSC_0614.JPG" height="426" title="Small and beautiful Coco island" width="640" /></a></div>
<div>
<br />
<i>Sunset on Anse Lazio beach(Praslin island):</i></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQIM4OlJCuQvKLxwB5IteAuWvufbBJtg5rYncXehhlrwvch4Mb2_K2nD3vUhTfsIU_9idu9ObNBX6tcOtAzM7KAFt1T3hoe2euCZHI6ragf8Axh6yjrkeZdMKM8FPJ_IQP-B1ynlJj44yh/s1600/DSC_0976.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Sunset on Anse Lazio beach(Praslin island)" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQIM4OlJCuQvKLxwB5IteAuWvufbBJtg5rYncXehhlrwvch4Mb2_K2nD3vUhTfsIU_9idu9ObNBX6tcOtAzM7KAFt1T3hoe2euCZHI6ragf8Axh6yjrkeZdMKM8FPJ_IQP-B1ynlJj44yh/s1600/DSC_0976.JPG" height="426" title="Sunset on Anse Lazio beach(Praslin island)" width="640" /></a></div>
<div>
<br />
<i>Grand Anse beach(La Digue island):</i><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM6PPt1ZkfW6XtK-HZydffRkgXuEav8OrGsTATvyjVdGKNovYsv6JycLD8LxmnVsSX5SGTeo-D66x2vXZEOXQr3em9ZT80MJLDe_vzoIadN_jnC6Egynww_zjhX97rrRpB4bb9ymdI4C9f/s1600/DSC_0185.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Grand Anse beach(La Digue island)" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM6PPt1ZkfW6XtK-HZydffRkgXuEav8OrGsTATvyjVdGKNovYsv6JycLD8LxmnVsSX5SGTeo-D66x2vXZEOXQr3em9ZT80MJLDe_vzoIadN_jnC6Egynww_zjhX97rrRpB4bb9ymdI4C9f/s1600/DSC_0185.JPG" height="426" title="Grand Anse beach(La Digue island)" width="640" /></a></div>
<br />
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-872448651648199532013-04-12T02:43:00.000-07:002013-04-12T02:48:02.912-07:00Good programmer is eternal studentProgramming is not like most other professions. Programmer can't allow himself to relax, because technologies is always moving forward.<br />
<br />
<div>
And if he does not follow this technologies, very soon, he will be useless for serious problems in IT world.<br />
<br />
<u>Good programmer is eternal student</u>. He always should be on the lookout for new and more innovative solution, even if he knows good old solution for the problem.<br />
<br />
How not to miss the right moment for changes?<br />
<ul>
<li>Always read news in your focus area</li>
<li>Read new books by competent authors</li>
<li>Follow great projects</li>
<li>Try new solutions for old problems</li>
</ul>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-87168896050417627732013-04-04T03:07:00.000-07:002013-09-01T02:33:48.788-07:00Git private repositories: GitHub vs Bitbucket<div dir="ltr" style="text-align: left;" trbidi="on">
I'm really enjoying to use <a href="https://github.com/" target="_blank">GitHub</a>. It's incredibly comfortable service for sharing code using <i>Git</i> public repositories. But when it comes to private repositories - prices are biting(22$/month for 20 private repositories).<br />
<div>
<br /></div>
<div>
That's why, i've decided to try <a href="https://bitbucket.org/" target="_blank">BitBucket</a> which suggests <u>unlimited</u> number of private repositories for 5 users.<br />
Besides, you can easily import you repositories, SSH keys etc. from <i>GitHub</i>.<br />
<br />
So, for me, <i>BitBucket</i> is the best place for private <i>Git</i> repositories. But for public repos, however, it's better to use <i>GitHub</i>, because it's the place where the community is. But who knows, maybe little by little community will be moved to <i>BitBucket</i> for public repositories too.</div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com1tag:blogger.com,1999:blog-6420587160424019844.post-85575865841566994112013-03-22T03:08:00.000-07:002013-04-12T02:48:45.121-07:00Classic ASP is HellAfter working for the long time with C#, ASP.NET MVC, Unit Tests, NuGet, and other pleasures of .NET life, i was assigned to the old Classic ASP project.<br />
<br />
I did not work with Classic ASP and VBScript before and i tell you now: <u>it is absolute Hell</u>.<br />
<br />
Now I realized how far is Microsoft progress in this direction in the last 10 years:<br />
<ul>
<li>C#- the most powerful Object Oriented language. It's even ahead of Java in many ways.</li>
<li>ASP.NET MVC - great framework for building lightweight, highly testable web-applications.</li>
</ul>
So, i am very happy that I did not catch the time when most web projects was written on Classic ASP.Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-66694209004360381652013-03-12T02:19:00.004-07:002013-03-12T02:19:49.435-07:00Preloading assemblies from Application folder in C#<div dir="ltr" style="text-align: left;" trbidi="on">
As you may know, <i>AppDomain.CurrentDomain.GetAssemblies()</i> returns list of assemblies that are loaded in current Application Domain. Even if your executing project has reference to some assembly there is no guarantee that this assembly has been already loaded. It will be loaded lazily on first use. But what if you need all assemblies now? For example, you want to search assemblies for classes that implement some interface or something else.<br />
<br />
You can easily force loading assemblies into your Application Domain.<br />
<br />
Let's create helper class to return list of all files in our Application folder(<i>Bin</i> folder in case of Web Application):<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> public static class From
{
public static IEnumerable<FileInfo> AllFilesIn(string path, bool recursively = false)
{
return new DirectoryInfo(path)
.EnumerateFiles("*.*", recursively ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
}
public static IEnumerable<FileInfo> AllFilesInApplicationFolder()
{
var uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
return AllFilesIn(Path.GetDirectoryName(uri.LocalPath));
}
}
</code></pre>
<br />
So, now you can preload assemblies as follows:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> From.AllFilesInApplicationFolder().Where(f => f.Extension == ".dll").ForEach(fi => Assembly.LoadFrom(fi.FullName));
</code></pre>
<br />
This solution is applicable both for Desktop and Web Applications.</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-17296945434787481482013-02-22T03:15:00.000-08:002013-02-22T03:18:33.314-08:00Safe forms without captcha - hybrid approach<div dir="ltr" style="text-align: left;" trbidi="on">
Captcha is very annoying for users. How can we make safe forms <u>without captcha</u>?<br />
<br />
<div>
Today's popular approaches are:<br />
<ul>
<li><b>CSS technique</b>. Idea about this is to create invisible field(hidden via CSS) in form. Silly spambots don't know that people can't see this field and fill it out. So, on server side you should make sure that this field is empty. </li>
<li><b>Javascript technique</b>. Idea about this is to generate and fill out some field using javascript. Silly spambots can't process javascript. So, on server side you should make sure that this field is not empty. This approach is good, but it has big disadvantage: if real user has javascript turned off he will not get this generated field, so he will not fill it out. Real user with disabled javascript = Silly spam bot. </li>
</ul>
Problem with this approaches: What if spam bot is Not Silly ?<br />
<br />
First approach is great in its simplicity, but i think that it is more easily for spam bots to overcome this obstacle, than second one. Javascript processing requires more brains in spambot head. So i like second approach more, but i do not like the fact that poor people with disabled javascript will suffer.<br />
<br />
I want not to bother user with captcha if he has javascript enabled. But if poor user has javascript disabled, he will get captcha(and spambot will get captcha too).<br />
<br />
<div>
So, my <b>hybrid approach</b> is to use captcha block(captcha image+ input field) wrapped in <i><noscript/></i> tags. And then use javascript to hide captcha block, remove <i><noscript/></i> tags, and fill out captcha with valid value.</div>
<div>
<br />
As result, we have captcha that is showing for users that have javascript disabled(as well as spambots). If user has javascript turned on, then captcha will be hidden and filled out using javascript. </div>
<div>
On server side we just check if captcha is valid- it is not matter for us whether user has javascript enabled!<br />
<br />
<br />
<br />
<br /></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-51509131124109485542013-02-02T10:16:00.002-08:002013-02-02T10:16:53.796-08:0010gen's MongoDB course - it was great! <div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Recently, I took a free course, organized by the 10gen company(it is famous for MongoDb NoSQL data-store). It was a great course that covered many interesting aspects about MongoDb. There are was video lectures, regular homeworks, and the final exam. You need 65% grade to pass course. I, actually, got 100% and earned beautiful "M101: MongoDB for Developers" certificate:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho3JwZZHJb7tt8MJ_x7IQ1R5SnPpmsuIVtcJDuKYr6yllFWyOD2Id-qzjDLAnF5Wnv2FVY9s_4_u4W98C6ANBrnZvBgRzWSsmRS8oSv1h4Mo0YpTAvRdqs2o2Z2WdOZo1wNPf7J071t4zZ/s1600/Untitled.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEho3JwZZHJb7tt8MJ_x7IQ1R5SnPpmsuIVtcJDuKYr6yllFWyOD2Id-qzjDLAnF5Wnv2FVY9s_4_u4W98C6ANBrnZvBgRzWSsmRS8oSv1h4Mo0YpTAvRdqs2o2Z2WdOZo1wNPf7J071t4zZ/s1600/Untitled.png" height="443" width="640" /></a></div>
<br />
Thank's very much to 10gen. They have not only created a great free product(MongoDb), but also help developers to learn it. </div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-82086799563049857242012-12-26T12:14:00.001-08:002012-12-26T12:14:24.269-08:00Implement GetHashCode() to track changed objects in C#<div dir="ltr" style="text-align: left;" trbidi="on">
Let's say we pull information about Movies from remote XML and save it in our database. Class that represent this objects can look like:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> public class Movie
{
public int Id { get; set; }
public string Name { get; set; }
public int? Duration { get; set; }
public int? Director { get; set; }
public int[] Actors { get; set; }
public int[] Genres { get; set; }
public int[] Countries { get; set; }
public string PosterUrl { get; set; }
public double? Rate { get; set; }
public int? Votes { get; set; }
public double? Imdb { get; set; }
public int? ImdbVotes { get; set; }
public string Site { get; set; }
public string Limits { get; set; }
public DateTime? Date { get; set; }
public string Description { get; set; }
public string Trailers { get; set; }
public string Company { get; set; }
}
</code></pre>
<div>
<br /></div>
Write operations are expensive if there are a lot of objects to be saved, so for performance reasons we should NOT save new object in database, if there is old object in database that is the same. So we need to extract object from databse and determine if new object differ from the old one. If objects are the same we DO NOT update it.<br />
<br />
But how to determine that objects are the same?<br />
<br />
Objects are differ if their contents differ. In our case we can clarify this as follows: <u>Objects are differ if their properties are differ</u>.<br />
<br />
Let's override <i>GetHashCode()</i> and <i>Equals()</i> methods to define how to check equality of 2 <i>Movie</i> objects:
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> public class Movie
{
public int Id { get; set; }
public string Name { get; set; }
public int? Duration { get; set; }
public int? Director { get; set; }
public int[] Actors { get; set; }
public int[] Genres { get; set; }
public int[] Countries { get; set; }
public string PosterUrl { get; set; }
public double? Rate { get; set; }
public int? Votes { get; set; }
public double? Imdb { get; set; }
public int? ImdbVotes { get; set; }
public string Site { get; set; }
public string Limits { get; set; }
public DateTime? Date { get; set; }
public string Description { get; set; }
public string Trailers { get; set; }
public string Company { get; set; }
public override int GetHashCode()
{
return HashCodeGenerator.Generate(Id, Name, Duration, Director, Actors, Genres, Countries, PosterUrl, Rate, Votes, Imdb, ImdbVotes, Site, Limits, Date, Description, Trailers, Company);
}
public override bool Equals(object obj)
{
return this.GetHashCode() == obj.GetHashCode();
}
}
</code></pre>
<br />
As you can see, we use custom class <i>HashCodeGenerator</i> to generate hash code from specified property values that we need to track.<br />
<br />
Implementation of this class:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> public static class HashCodeGenerator
{
public static int Generate(params object[] objects)
{
unchecked
{
var offset = 13;
var compositionOffset = 7;
foreach (object obj in objects)
{
if (obj==null)
continue;
if (obj is Array)
{
var array = obj as Array;
foreach (var item in array)
{
offset = (offset * compositionOffset) + item.GetHashCode();
}
}
else
{
offset = (offset * compositionOffset) + obj.GetHashCode();
}
}
return offset;
}
}
}
</code></pre>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-10675859419789479662012-12-19T11:52:00.001-08:002013-09-01T02:32:51.485-07:00Using expression trees to get rid of "magic" strings in C#<div dir="ltr" style="text-align: left;" trbidi="on">
"Magic" strings may appear in programming code in many cases. For example, if we need to pass property names to some method.<br />
<br />
Let's say we need to make <i>DatabaseIndexCreator</i> class that creates database index for specified property name(or properties, if index is compound) of some model(in our example it's <i>Person</i> class):<br />
<div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> public class Person
{
public string Name { get; set; }
public string Surname { get; set; }
public bool Sex { get; set; }
}
</code></pre>
<br /></div>
So, we end up with function that accept property names as strings:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> public class DatabaseIndexCreator<TEntity>
{
public void CreateIndex(string[] fields)
{
//creating index
}
}
</code></pre>
<br />
And use this class like this:<br />
<div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> DatabaseIndexCreator<Person> indexCreator = new DatabaseIndexCreator<Person>();
//creating simple index:
indexCreator.CreateIndex(new[] { "Name" });
//creating compound index:
indexCreator.CreateIndex(new[] { "Name", "Sex" });
</code></pre>
</div>
<br />
It's bad design, because you can forget to rename this "magic" strings after renaming properties of <i>Person</i> class.<br />
<br />
But you can use <u>Expression Trees</u> - nice C# feature to get rid of this "magic" strings in your code.<br />
<br />
Let's create class with extension method for <i>Expression<Func<T, U>></i> expression:<br />
<div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> public static class ExpressionEx
{
public static HashSet<string> AsMemberExpressionKeys<T, U>(this Expression<Func <T, U>> index)
{
var exp = index.Body as NewExpression;
var keys = new HashSet<string>();
if (exp != null)
{
foreach (var x in exp.Arguments.OfType<MemberExpression>())
{
keys.Add(GetPropertyAlias(x));
}
}
else if (index.Body is MemberExpression)
{
var me = index.Body as MemberExpression;
keys.Add(GetPropertyAlias(me));
}
return keys;
}
private static string GetPropertyAlias(MemberExpression mex)
{
var retval = "";
var parentEx = mex.Expression as MemberExpression;
if (parentEx != null)
{
retval += GetPropertyAlias(parentEx) + ".";
}
retval += mex.Member.Name;
return retval;
}
}
</code></pre>
<br />
<u>What benefits can we get from this tricky extension method?</u><br />
<br />
Now we can refactor our <i>DatabaseIndexCreator</i> class like this:</div>
<div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> public class DatabaseIndexCreator<TEntity>
{
public void CreateIndex<TReturn>(Expression<Func<TEntity, TReturn>> exp)
{
string[] fields = exp.AsMemberExpressionKeys().ToArray();
//creating index(simple or compound)
}
}
</code></pre>
</div>
<div>
<br /></div>
<div>
And use this class like this:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> DatabaseIndexCreator<Person> indexCreator = new DatabaseIndexCreator<Person>();
//creating simple index:
indexCreator.CreateIndex(t => t.Name);
//creating compound index:
indexCreator.CreateIndex(t => new {t.Name, t.Sex});
</code></pre>
<br />
As you see, there is no more "magic" strings, that is very good for our code design and our nerves.</div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0tag:blogger.com,1999:blog-6420587160424019844.post-70269204706929055872012-12-12T09:29:00.000-08:002013-09-01T02:32:26.598-07:00Redirect www subdomain to root domain in ASP.NET<div dir="ltr" style="text-align: left;" trbidi="on">
Let's say we want to perform permanent redirect from <i>http://www.example.com </i>address to <i>http://example.com </i>in our ASP.NET application for SEO purposes(URL canonization).<br />
<br />
<div>
First of all, we need to download <i>Rewrite module</i> for IIS7:<br />
<a href="http://www.microsoft.com/web/gallery/install.aspx?appid=urlrewrite2"></a><a href="http://www.microsoft.com/web/gallery/install.aspx?appid=urlrewrite2">http://www.microsoft.com/web/gallery/install.aspx?appid=urlrewrite2</a></div>
<div>
<br />
Then you need to open <i>IIS Manager</i> and navigate to <i>URL Rewrite </i>section.</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieEvwdKB1wcoas5l8epywh2f8NKL_mEdk0E-BDEiOe8aw1g9ngSptZOhyphenhyphenut5HozZlrrtIrOEHK-2Iquhf13M4Fjdu18FRjEgBvwIyjdIHyoQc1cuCEHApe79NFEOeoHG5kru7-T1hLBb27/s1600/rewrite.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieEvwdKB1wcoas5l8epywh2f8NKL_mEdk0E-BDEiOe8aw1g9ngSptZOhyphenhyphenut5HozZlrrtIrOEHK-2Iquhf13M4Fjdu18FRjEgBvwIyjdIHyoQc1cuCEHApe79NFEOeoHG5kru7-T1hLBb27/s640/rewrite.png" height="553" width="640" /></a></div>
<div>
<br /></div>
After proper configuration in <i>IIS Manager </i>you'll get section in your Web.config that can look like:<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRjo8lQZIS0401oInrJxtlxqaZetiuQsHvL0kCnWHRzSKqQCJ-DJ-Kfu-eKOOn82fgfdXBb8CtpHBwKtoFYzvyay8U9KD897HJ-f25ZkPt5h-HbpA9xv0k_X95cxV8uW-gYukCfMer8bM1/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;"> <configuration>
<system.webServer>
<rewrite>
<rules>
<rule name ="CanonicalHostNameRule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input ="{HTTP_HOST}" pattern="^www\." negate="false" />
</conditions>
<action type ="Redirect" url="http://example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
</code></pre>
<div>
<span style="-webkit-text-decorations-in-effect: initial; border-collapse: separate; border-spacing: 0px; font-family: Tahoma; text-align: -webkit-auto;"><span style="font-family: Calibri; font-size: 15px;"><br /></span></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/09445688579276261453noreply@blogger.com0