<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Less pain in your's development hands - Oleksii's Blog</title>
 <link href="http://www.oleksiy.pro/atom.xml" rel="self"/>
 <link href="http://www.oleksiy.pro"/>
 <updated>2012-12-27T06:26:53-08:00</updated>
 <id>http://www.oleksiy.pro</id>
 <author>
   <name>Oleksii Glib</name>
   <email>contact@oleksiy.pro</email>
 </author>

 
 <entry>
   <title>Cordova (PhoneGap) iOS Security</title>
   <link href="http://www.oleksiy.pro/2012/12/27/cordova-ios-security"/>
   <updated>2012-12-27T00:00:00-08:00</updated>
   <id>hhttp://www.oleksiy.pro/2012/12/27/cordova-ios-security</id>
   <content type="html">&lt;p&gt;Almost a year ago I wrote an article about &lt;a href='/2011/09/20/phonegap-application-encryption/' title='PhoneGap (newely Cordova'&gt;securing PhoneGap source files on iOS platform&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There were a lot of questions, and private emails, that&amp;#8217;s why I have actualized the description a bit, and made new manual.&lt;/p&gt;

&lt;p&gt;NOTE: using this method will not secure your javascript code 100%, but will help a lot to protect it from a lot of hackers. This methid ONLY works for iOS.&lt;/p&gt;

&lt;h2 id='the_idea'&gt;The idea&lt;/h2&gt;

&lt;p&gt;The main idea at the moment contain 2 steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Prepare single-file application inside &lt;code&gt;index.html&lt;/code&gt; and encrypt it with key.&lt;/li&gt;

&lt;li&gt;Put decryption mechanism into XCode application while loading the html.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At step #1 better to embed all CSS, JS and even images into one file, so it will a hacker less holes to get in.&lt;/p&gt;

&lt;p&gt;At step #2 your encryption key will be stored in binary mode, so only very experienced hackers will try to find it.&lt;/p&gt;

&lt;h2 id='preparing_indexhtml'&gt;Preparing index.html&lt;/h2&gt;

&lt;p&gt;Once you have developed your application with cordova, we need to encrypt it. For this purpose I have made a small tool, as previously a lot of things was not working in right way.&lt;/p&gt;

&lt;p&gt;To install the tool, you should install &lt;a href='http://nodejs.org/' title='NodeJS'&gt;NodeJS&lt;/a&gt; and &lt;a href='https://npmjs.org/' title='NPM'&gt;NPM&lt;/a&gt; like it described &lt;a href='http://shapeshed.com/setting-up-nodejs-and-npm-on-mac-osx/' title='Setting Up Node.js and Npm on Mac OSX'&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Then you should install my small tool &lt;a href='https://npmjs.org/package/cordovacrypt' title='Cordova Crypt Tool'&gt;corc&lt;/a&gt; through Mac OS terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install -g cordovacrypt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Maybe, you will need to use &lt;code&gt;sudo&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To run encryption you should execute:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;corc KEY FILEIN [FILEOUT]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;KEY - your key without spaces and any bash illegal symbols.&lt;/li&gt;

&lt;li&gt;FILEIN - path to the index.html file which should be encrypted.&lt;/li&gt;

&lt;li&gt;FILEOUT - optional parameter where to save encrypted file. If not specified, original will be rewritten.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;corc mySecretKey index_original.html index.html&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now you have prepared index.html file.&lt;/p&gt;

&lt;h2 id='making_changes_to_xcode_application'&gt;Making changes to XCode application&lt;/h2&gt;

&lt;p&gt;Make sure, you have created a new Cordova application like it is written &lt;a href='http://docs.phonegap.com/en/2.2.0/guide_getting-started_ios_index.md.html' title='PhoneGap: Getting Started with iOS'&gt;here&lt;/a&gt;, and make next steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Once the application is ready, open project inside XCode, and go to the &lt;code&gt;Project Navigator&lt;/code&gt;.&lt;/li&gt;

&lt;li&gt;There you will see the &lt;code&gt;www&lt;/code&gt; item, &lt;code&gt;*YourProjectname*.xcodeproj&lt;/code&gt;, etc.&lt;/li&gt;

&lt;li&gt;Unfold &lt;code&gt;.xcodeproj&lt;/code&gt; item and than &lt;code&gt;Classes&lt;/code&gt; &amp;gt; &lt;code&gt;Cleaver&lt;/code&gt; and select &lt;code&gt;CDVViewController.m&lt;/code&gt;.&lt;/li&gt;

&lt;li&gt;In the center you will see the source code of &lt;code&gt;CDVViewController.m&lt;/code&gt;.&lt;/li&gt;

&lt;li&gt;Find the line &lt;code&gt;- (void)viewDidLoad&lt;/code&gt;. This is a method on view loading.&lt;/li&gt;

&lt;li&gt;Scroll down to the end of this method (the last &lt;code&gt;if&lt;/code&gt; statement), where will be the line: &lt;code&gt;if (!loadErr) {&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You should remove everything inside this &lt;code&gt;if&lt;/code&gt; statement, except body of &lt;code&gt;else&lt;/code&gt; statement. And paste next code into &lt;code&gt;if&lt;/code&gt; statement:&lt;/p&gt;
&lt;div data-file='gistfile2.m' class='gc' data-id='4387663'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This code will hook the index.html load and give it a different content.&lt;/p&gt;

&lt;p&gt;Now after the method &lt;code&gt;viewDidLoad&lt;/code&gt; (or before, it is up to you), insert 2 more service methods, which will actually decode the encrypted index.html:&lt;/p&gt;
&lt;div data-file='gistfile1.m' class='gc' data-id='4387663'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In line 17 you may see a strange string &lt;code&gt;ffffffffffffffffffffffff&lt;/code&gt; - this is your encryption password. Replce it with yours.&lt;/p&gt;

&lt;p&gt;The last thing you should add into this file are two includes. Go to the top of the file, and after all &lt;code&gt;#import&lt;/code&gt; directives add:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;#import &amp;lt;CommonCrypto/CommonCryptor.h&amp;gt;&lt;/code&gt;&lt;/li&gt;

&lt;li&gt;&lt;code&gt;#import &amp;lt;CommonCrypto/CommonDigest.h&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At this point you can compile the code and see that it is working!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Belz. Using AppHarbor as .Net worker mule</title>
   <link href="http://www.oleksiy.pro/2012/05/10/belz-using-appharbor-as-donet-worker-mule"/>
   <updated>2012-05-10T00:00:00-07:00</updated>
   <id>hhttp://www.oleksiy.pro/2012/05/10/belz-using-appharbor-as-donet-worker-mule</id>
   <content type="html">&lt;p&gt;We are living at a time, when everyday brings something brand new and fantastic. For a lot of time already I am keeping an eye on &lt;a href='https://appharbor.com/'&gt;AppHarbor&lt;/a&gt; service. Shared .Net hosting became free and usable. More than that, AppHarbor allows you to run not only websites, but daemons (services/workers), which are created from simple console application.&lt;/p&gt;

&lt;p&gt;Lately, I have discovered &lt;a href='http://www.iron.io/'&gt;Iron.IO&lt;/a&gt;, which provides stable distributed messaging protocol, and even dynamic workers module. Unfortunately, they do not support .Net for workers yet. This article provides an information on how to implement almost free daemon for your needs.&lt;/p&gt;

&lt;h2 id='design'&gt;Design&lt;/h2&gt;

&lt;p&gt;When you need a background process to process some jobs, the main parts of it should be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Queue of messages;&lt;/li&gt;

&lt;li&gt;API calls to messages queue to enqueue/dequeue messages;&lt;/li&gt;

&lt;li&gt;Daemon application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, all these parts could be made/used with almost no cost involved.&lt;/p&gt;

&lt;h2 id='queue_of_messages'&gt;Queue of messages&lt;/h2&gt;

&lt;p&gt;With all today tools and services, there is no need to develop bicycle again and again. There already are numerous count of services, which provides queue messaging with even no cost for starting project.&lt;/p&gt;

&lt;p&gt;Everything I have investigated, are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://www.iron.io/products/mq'&gt;IronMq&lt;/a&gt;;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://www.cloudamqp.com/'&gt;CloudAMQP&lt;/a&gt; (RabbitMQ code inside)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both of them are almost the same, but I recon API of IronMq is a bit better.&lt;/p&gt;

&lt;h2 id='api_calls_to_messaging_queue'&gt;API calls to messaging queue&lt;/h2&gt;

&lt;p&gt;To manage the queue, we need an API connection to it. IronMQ provides such functionality with next methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enqueue message(s);&lt;/li&gt;

&lt;li&gt;Dequeue message(s).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More than that, after dequeue from IronMq, message is not deleted from server actually, but waits a timeout to be returned back (for example your code has an exception). It will be removed from server only after deletion of message.&lt;/p&gt;

&lt;p&gt;NOTE: IronMQ is a paid service, where 10000 requests costs 1 US cent (the price for today). If you are requesting queue to check for messages every second, it will cost you about 3 US dollars per month. If you are processing a lot of messages during each request - that is not a price for good service.&lt;/p&gt;

&lt;h2 id='daemon_application'&gt;Daemon application&lt;/h2&gt;

&lt;p&gt;This is the most sweet part of whole article. You can create a separate windows service, which will work as daemon. Inside daemon, it will be good to create several parallel threads for workers. Best way would be, if your daemons are set up on different servers, to scale the work. And surely, you need to host it somewhere.&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s code some worker, which will calculate fibonacci value and push the result to your iPhone, through &lt;a href='http://www.prowlapp.com/'&gt;Prowl&lt;/a&gt;. My proposal is using AppHarbor as daemon hosting and IronMq as message queue service. As daemon kernel, we will use &lt;a href='https://github.com/acropolium/Belz'&gt;Belz&lt;/a&gt; project.&lt;/p&gt;

&lt;h2 id='10_minutes_of_development'&gt;10 minutes of development&lt;/h2&gt;

&lt;p&gt;First of all you have to register an account at AppHarbor.&lt;/p&gt;

&lt;p&gt;Now login to the system and inside &amp;#8220;Applications&amp;#8221; section create an application &amp;#8220;Belz Try&amp;#8221;.&lt;/p&gt;

&lt;p&gt;Go to &amp;#8220;Addons&amp;#8221; section, and select IronMQ addon to be installed. Inside &amp;#8220;Configuration variables&amp;#8221; section, you will find settings for your IronMq queue project.&lt;/p&gt;

&lt;p&gt;Now a bit of coding. Copy the repository url and make git clone from it.&lt;/p&gt;

&lt;p&gt;Next step to create a new solution inside cloned directory from Visual Studio.&lt;/p&gt;

&lt;p&gt;After creation of solution, be sure, you have NuGet installed (this will make your life easier). Create console application inside solution, and add next NuGet packages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Belz.QueueProvider.IronMq;&lt;/li&gt;

&lt;li&gt;Belz.QueueProvider;&lt;/li&gt;

&lt;li&gt;Belz;&lt;/li&gt;

&lt;li&gt;Prowlin (for prowl notifications);&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, modify your Program.cs to look like this:&lt;/p&gt;
&lt;div data-file='01.cs' class='gc' data-id='2653956'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Don&amp;#8217;t forget to change API keys and tokens to use app.&lt;/p&gt;

&lt;p&gt;After this step, commit and push your AppHarbor daemon to server.&lt;/p&gt;

&lt;p&gt;And you are done.&lt;/p&gt;

&lt;h2 id='testing'&gt;Testing&lt;/h2&gt;

&lt;p&gt;I have created a sample application to put some work into queue:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ConsoleApplication1.exe 13&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will put number 13 to be calculated for fibonacci by our daemon, and sent to iPhone through Prowl service.&lt;/p&gt;

&lt;p&gt;The code of application is simple:&lt;/p&gt;
&lt;div data-file='02.cs' class='gc' data-id='2653956'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It require next NuGet Packages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Belz.QueueProvider.IronMq;&lt;/li&gt;

&lt;li&gt;Belz.QueueProvider;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='big_notice'&gt;Big notice&lt;/h2&gt;

&lt;p&gt;Don&amp;#8217;t forget to switch off your test daemon, because in sometime if you reach out free requests, IronIO will bill you for this.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Extending Migrator.NET with logic scopes</title>
   <link href="http://www.oleksiy.pro/2012/03/12/extending-migratordotnet-with-scopes"/>
   <updated>2012-03-12T00:00:00-07:00</updated>
   <id>hhttp://www.oleksiy.pro/2012/03/12/extending-migratordotnet-with-scopes</id>
   <content type="html">&lt;p&gt;&lt;a href='http://code.google.com/p/migratordotnet/'&gt;Migrator.NET&lt;/a&gt; (or at &lt;a href='https://github.com/migratordotnet/Migrator.NET'&gt;GitHub&lt;/a&gt;) is a well-known migration tool for &lt;code&gt;.Net Framework&lt;/code&gt;. For already a years this lib is stable and much better than even today&amp;#8217;s &lt;code&gt;Entity Framework&lt;/code&gt; migrations. It is also very hard to add something new to the already good thing, but some time ago I have a need to extend it&amp;#8217;s functionality.&lt;/p&gt;

&lt;h2 id='the_aim'&gt;The Aim&lt;/h2&gt;

&lt;p&gt;You should know, that the usual way of working with db migrations is manual upgrade of db scheme. So, when your project is big enough and has no unpredicted parts, the &lt;code&gt;Migrator.Net&lt;/code&gt; is what you really need.&lt;/p&gt;

&lt;p&gt;In my case, there was a project, which should contain different db structures in different modules. Modules may be written by different people, and you can understand what a nightmare can be to allow all of them using 1-2-3 versioning system, which is default today. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;we have 2 modules &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt;, which are supported by 2 different people;&lt;/li&gt;

&lt;li&gt;&lt;code&gt;A&lt;/code&gt; has got a migration &lt;code&gt;2012031200&lt;/code&gt; (timestamp for the version &lt;code&gt;YYYYMMDDHH&lt;/code&gt;) on Monday;&lt;/li&gt;

&lt;li&gt;the developer of &lt;code&gt;B&lt;/code&gt; saw it and added a migration &lt;code&gt;2012031300&lt;/code&gt; on Tuesday to module &lt;code&gt;B&lt;/code&gt;;&lt;/li&gt;

&lt;li&gt;on Wednesday the developer of &lt;code&gt;A&lt;/code&gt; has added new migration &lt;code&gt;2012031400&lt;/code&gt;;&lt;/li&gt;

&lt;li&gt;when system is launched, it should run all latest migrations to make a db scheme actualized.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You must notice, that migrations of both modules are not changing each other tables, but only their own needed structures.&lt;/p&gt;

&lt;p&gt;And here will be a problem, if Tuesday migration failed, Wednesday migration will not run at all. That&amp;#8217;s why we should dedicate separate logical spaces for each logical module.&lt;/p&gt;

&lt;h2 id='the_proposal'&gt;The Proposal&lt;/h2&gt;

&lt;p&gt;First of all the task was to remain backward compatibility, so for the end developer there will not be a difference with scope or without it.&lt;/p&gt;

&lt;p&gt;Than I have added a new parameter to migration attribute:&lt;/p&gt;
&lt;div data-file='01.cs' class='gc' data-id='2023088'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And after this, if you want to migrate to latest, you have to specify the scope name of the migrations. A list of scopes can be fetched with &lt;code&gt;Scopes&lt;/code&gt; property of &lt;code&gt;Migrator&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;If you wish to apply all migrations from all scopes, use &lt;code&gt;MigrateAllScopesToLastVersion&lt;/code&gt; method inside &lt;code&gt;Migrator&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;Modified version of &lt;code&gt;Migrator.NET&lt;/code&gt; is available at &lt;a href='https://github.com/acropolium/Migrator.NET'&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id='easter_egg'&gt;Easter Egg&lt;/h2&gt;

&lt;p&gt;If you specify a scope as empty string, code will not detect scope automatically, but will return the default scope (32 zeroes).&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Using MvcMiniProfiler with NancyFX</title>
   <link href="http://www.oleksiy.pro/2012/03/05/using-mvcminiprofiler-with-nancyfx"/>
   <updated>2012-03-05T00:00:00-08:00</updated>
   <id>hhttp://www.oleksiy.pro/2012/03/05/using-mvcminiprofiler-with-nancyfx</id>
   <content type="html">&lt;p&gt;Lately, some new interesting web-development frameworks appeared based on mvc concept. Some of them are totally new experience, but others are using the best experience from different technologies and languages.&lt;/p&gt;

&lt;h2 id='ruby_on_rails_clones'&gt;Ruby On Rails Clones&lt;/h2&gt;

&lt;p&gt;&lt;a href='http://www.sinatrarb.com/'&gt;Sinatra&lt;/a&gt; - is one of the smoothest and intelligent frameworks I&amp;#8217;ve ever seen. When Ruby became famous, a lot of things were ported from this language, to others. I&amp;#8217;ve even investigated a PHP port named &lt;a href='http://www.slimframework.com/'&gt;Slim Framework&lt;/a&gt;, and it is really fantastic as for PHP.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://nancyfx.org/'&gt;NancyFX&lt;/a&gt; has appeared at the end of 2010 and day-by-day they have damage the brain of the C# coding society (the web development part). With this, many interesting tools as &lt;a href='http://code.google.com/p/mvc-mini-profiler/'&gt;MiniProfiler&lt;/a&gt;, should be also available for use with NancyFX.&lt;/p&gt;

&lt;h2 id='nancyfx_and_miniprofiler'&gt;NancyFX and MiniProfiler&lt;/h2&gt;

&lt;p&gt;On some stage of coding with &lt;code&gt;NancyFX&lt;/code&gt;, I&amp;#8217;ve got a need to measure the performance of it. There were no doubts, that &lt;code&gt;MvcMiniProfiler&lt;/code&gt; will do the job. As I have not found a working solution for this, I&amp;#8217;m posting it here.&lt;/p&gt;

&lt;p&gt;All you need to do, is create a custom bootstrap for &lt;code&gt;NancyFX&lt;/code&gt;. How to make it, please read &lt;a href='https://github.com/NancyFx/Nancy/wiki/Bootstrapper'&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Than you have to override some methods of custom bootstrap, so the profiler will be injected into code.&lt;/p&gt;
&lt;div data-file='01.cs' class='gc' data-id='1977951'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;MvcMiniProfiler is describing how to inject the header into template and how to run tests very good on their site, so I am not touching this theme.&lt;/p&gt;

&lt;p&gt;The example of profiler usage:&lt;/p&gt;
&lt;div data-file='02.cs' class='gc' data-id='1977951'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>PhoneGap (newely Cordova) Application Encryption</title>
   <link href="http://www.oleksiy.pro/2011/09/20/phonegap-application-encryption"/>
   <updated>2011-09-20T00:00:00-07:00</updated>
   <id>hhttp://www.oleksiy.pro/2011/09/20/phonegap-application-encryption</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;This article is deprecated, please read the fresh one&lt;/strong&gt; &lt;a href='/2012/12/27/cordova-ios-security/' title='Cordova (PhoneGap'&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This time I am writing about PhoneGap Application security.&lt;/p&gt;

&lt;p&gt;It happened that I was involved into a simple iPhoneApp development. The reason, why we have selected PhoneGap is simple - nobody knows Objective C. So, during a month team was developing an iPhone application with PhoneGap API. And when we have got a first compilable and functional sample, it occurs, that &amp;#8220;app&amp;#8221; file could be unpacked as zip archive, and all our javascript is visible and readable.&lt;/p&gt;

&lt;p&gt;There were 2 solutions we could jump into:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Move to Objective C&lt;/li&gt;

&lt;li&gt;Secure the javascript code&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Item #1 for our team was complicated and long in time to learn.&lt;/p&gt;

&lt;p&gt;Item #2 could be a way, but there was a need to read secured code from PhoneGap-based application. So, here was also 2 ways - secure with javascript encryption like &lt;a href='http://utf-8.jp/public/jjencode.html' title='JJEncode'&gt;JJEncode&lt;/a&gt;, or to encrypt javascript, which will be inside &lt;code&gt;app&lt;/code&gt; file, and decrypt it in memory on application lunch and put into WebView context. And we have took the second way.&lt;/p&gt;

&lt;h2 id='the_way'&gt;The Way&lt;/h2&gt;

&lt;p&gt;Now let me explain the method, how in theory the encryption is made.&lt;/p&gt;

&lt;p&gt;We have some build scripts, and nobody is working in XCode with javascript and html. All of us are using favorite source editors for it. XCode is used only to build a project for deployment and test. So, we have build scripts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Script is parsing &lt;code&gt;index.html&lt;/code&gt;, and include all references to javascript/css/images inside this one html file. In this way, we have bundled application inside one index.html file.&lt;/li&gt;

&lt;li&gt;Script is encrypting &lt;code&gt;index.html&lt;/code&gt; with &lt;code&gt;AES 256bit&lt;/code&gt; encryption and put this file into XCode project as resource (please, note this).&lt;/li&gt;

&lt;li&gt;XCode build is running and generating app-file.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id='phonegap_patch'&gt;PhoneGap Patch&lt;/h2&gt;

&lt;p&gt;The PhoneGap library was patched to support decoding of the index.html with provided key and load this memory block into WebView. I have shared the modifiew PhoneGap sourcecode at &lt;a href='https://github.com/ioleksiy/phonegap-iphone' title='PhoneGap iPhone'&gt;Github&lt;/a&gt;. To use it, you should manually build the library from sourcecode and install it. Don&amp;#8217;t forget, that PhoneGap library now is trying to search for an encrypted &amp;#8220;index.html&amp;#8221; resource file.&lt;/p&gt;

&lt;h2 id='providing_key'&gt;Providing Key&lt;/h2&gt;

&lt;p&gt;Sure, you need to provide key for patched PhoneGap framework to decrypt your source code.&lt;/p&gt;

&lt;p&gt;Inside your &lt;code&gt;AppDelegate.m&lt;/code&gt; file, add a method:&lt;/p&gt;
&lt;div data-file='01.m' class='gc' data-id='1960145'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here you see, that your&amp;#8217;s 256bit key is 32 &lt;code&gt;f&lt;/code&gt; symbols.&lt;/p&gt;

&lt;h2 id='you_see_the_finish'&gt;You see the finish&lt;/h2&gt;

&lt;p&gt;Yes, that is all. Now your&amp;#8217;s html will be decrypted and loaded into WebView on iApp start, and there will not be files unsecured insude your app.&lt;/p&gt;

&lt;p&gt;That is right, that someone can decompile objective c code to find out the key, but this is a bit harder than if you show all your sources from zip.&lt;/p&gt;

&lt;h2 id='ps'&gt;P.S.&lt;/h2&gt;

&lt;p&gt;At the end, maybe you will need a method to encrypt your html file. I have it only for php:&lt;/p&gt;
&lt;div data-file='02.php' class='gc' data-id='1960145'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Another RestAPI accessor for .Net</title>
   <link href="http://www.oleksiy.pro/2010/07/03/another-restapi-accessor-for-net"/>
   <updated>2010-07-03T00:00:00-07:00</updated>
   <id>hhttp://www.oleksiy.pro/2010/07/03/another-restapi-accessor-for-net</id>
   <content type="html">&lt;p&gt;Some time has passed after I have launched the open-source library to access &lt;a href='/2010/06/17/google-storage-api-with-c-sharpgs-try-it/' title='Google Storage API with C#. SharpGs. Try it'&gt;Google Storage Rest Api&lt;/a&gt;. By that time there was a problem accessing the REST service of google. The solution I have found was a great library named &lt;a href='http://restsharp.org/' title='RestSharp'&gt;RestSharp&lt;/a&gt;. On the first glance it came, that library is very handy and lightweight. For sure, developers of it are great people and professionals. But, when it came to customize the RestClient for GS api needs, it found out that it is very hard and not intuitive to extend the flexibility of this library.&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s why I have developed some small and light solution for simple RestApi requests. Have named it &lt;a href='http://github.com/ioleksiy/Rest4Net' title='Rest4Net on Github'&gt;Rest4Net&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id='the_body'&gt;The body&lt;/h2&gt;

&lt;p&gt;The most of the functionality you need to do, is to inherit your class from &lt;a href='http://github.com/ioleksiy/Rest4Net/blob/master/Rest4Net/Connector.cs' title='Rest4Net.Connector Example Code'&gt;Rest4Net.Connector&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And that&amp;#8217;s almost all. You need to implement constructor and methods, your client class will return.&lt;/p&gt;

&lt;p&gt;If response from the server is &lt;code&gt;Xml&lt;/code&gt; or &lt;code&gt;Json&lt;/code&gt;, this library can parse response into object (like deserialisation). If you need some array field, mark it as &lt;code&gt;IList&amp;lt;&amp;gt;&lt;/code&gt; please.&lt;/p&gt;

&lt;p&gt;For example, I have made an implementation of &lt;a href='http://bit.ly/' title='Bit.ly Service'&gt;Bit.ly&lt;/a&gt; service client &lt;a href='http://github.com/ioleksiy/SharpBitLy' title='Bit.ly connector on Github'&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;How to use the service demo application is &lt;a href='http://github.com/ioleksiy/SharpBitLy/blob/master/SharpBitLy.Demo/Program.cs' title='Demo application on Github'&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope, this library will help someone. ;)&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Google Storage API with C#. SharpGs. Try it</title>
   <link href="http://www.oleksiy.pro/2010/06/17/google-storage-api-with-c-sharpgs-try-it"/>
   <updated>2010-06-17T00:00:00-07:00</updated>
   <id>hhttp://www.oleksiy.pro/2010/06/17/google-storage-api-with-c-sharpgs-try-it</id>
   <content type="html">&lt;p&gt;Today I have great news for you - &lt;a href='https://github.com/acropolium/SharpGs' title='Locate sources on github'&gt;SharpGs&lt;/a&gt;, is a first open-source C# library to access &lt;code&gt;Google Storage API&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Why have I done that - maybe for fun and interest of Google products. But the real idea was that now I have something new to share and give to society, and became alive in my blog :).&lt;/p&gt;

&lt;h2 id='how_to_use'&gt;How to use&lt;/h2&gt;

&lt;p&gt;Here will be the small instruction on how to use the library. On the GitHub you will find a &lt;a href='https://github.com/acropolium/SharpGs/blob/master/SharpGsDemo/Program.cs' title='Example on github'&gt;demo project&lt;/a&gt; with the main function calls. So, here is the instruction:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First of all you need to get invite or right to access this beta-testing launch of SharpGs.&lt;/li&gt;

&lt;li&gt;&lt;a href='https://sandbox.google.com/storage/m/manage' title='Create new access key'&gt;Here&lt;/a&gt; you need to create new access key pair (open key and a secret to crypt verification data).&lt;/li&gt;

&lt;li&gt;In your code create a new instance of &lt;code&gt;SharpGsClient&lt;/code&gt; class and pass key and secret, you have got from step 2. And you are done :)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To get the list of buckets from the server, use the &lt;code&gt;Buckets&lt;/code&gt; property of &lt;code&gt;SharpGsClient&lt;/code&gt; instance object. This property provides the enumeration of &lt;code&gt;IBucket&lt;/code&gt; interface objects, which has properties of bucket information or methods to operate with bucket objects.&lt;/p&gt;

&lt;p&gt;Each call of the method could throw an exception if something goes wrong. The list of supported exceptions will be increased in a time.&lt;/p&gt;

&lt;p&gt;I think this library is too simple to make tons of examples, so, if there will be questions, I will answer them in comments or other post.&lt;/p&gt;

&lt;p&gt;Sorry, for leak of comments inside the code, hope they will appear there soon.&lt;/p&gt;

&lt;p&gt;Have a nice try!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>AcroDB. Business Logic</title>
   <link href="http://www.oleksiy.pro/2010/04/13/acrodb-business-logic"/>
   <updated>2010-04-13T00:00:00-07:00</updated>
   <id>hhttp://www.oleksiy.pro/2010/04/13/acrodb-business-logic</id>
   <content type="html">&lt;p&gt;Previously I have talked only about entity creation and maintain. But what if we need to add some business logic to this entity. For example, we have a table of Pages, and you need to fetch all cities of some country?&lt;/p&gt;

&lt;h2 id='preparation'&gt;Preparation&lt;/h2&gt;

&lt;p&gt;First of all we need never to forget, that all &lt;code&gt;AcroDB&lt;/code&gt; entities are lazy-loaded and each of them contains a reference to the &lt;code&gt;AcroDataContext&lt;/code&gt;, that created them. And if you want to save an integrity, you need to use the same &lt;code&gt;AcroDataContext&lt;/code&gt; when fetching new entities. So, how will we do?&lt;/p&gt;

&lt;h2 id='entity_creation'&gt;Entity creation&lt;/h2&gt;

&lt;p&gt;The first step was written before is the entity creation:&lt;/p&gt;
&lt;div data-file='01.cs' class='gc' data-id='1960224'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id='business_logic'&gt;Business logic&lt;/h2&gt;

&lt;p&gt;Under the interface we have small problem, which is we can&amp;#8217;t implement methods. So, we need to create separate classes of business logic, or to write extension methods. I used to implement extension method for the interface:&lt;/p&gt;
&lt;div data-file='02.cs' class='gc' data-id='1960224'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You may notice the extension method &lt;code&gt;AcroContext()&lt;/code&gt;. To use it you need to reference &lt;code&gt;AcroDB.Helpers&lt;/code&gt; namespace. This method returns the link to data context that was attached to entity.&lt;/p&gt;

&lt;h2 id='the_result'&gt;The result&lt;/h2&gt;

&lt;p&gt;So, in result you could call:&lt;/p&gt;
&lt;div data-file='03.cs' class='gc' data-id='1960224'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And all children of the page will be fetched from DB.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>AcroDB. How to use</title>
   <link href="http://www.oleksiy.pro/2010/03/26/acrodb-how-to-use"/>
   <updated>2010-03-26T00:00:00-07:00</updated>
   <id>hhttp://www.oleksiy.pro/2010/03/26/acrodb-how-to-use</id>
   <content type="html">&lt;p&gt;Hi, all! Almost a week have passed, after I have &lt;a href='/2010/03/20/acrodb-the-beginning/' title='AcroDB. The beginning'&gt;posted&lt;/a&gt; my new flexible provider article. Maybe, nobody commented it, because of article compicity&amp;#8230; So, today I will try to show you, how to use &lt;a href='http://github.com/ioleksiy/AcroDB' title='Fork it on Github'&gt;AcroDb&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id='the_model'&gt;The model&lt;/h2&gt;

&lt;p&gt;Usually, when you start to design your future application, you need to describe 3 levels of MVC, and first of it goes the model layer. For the simple projects, the model layer consists of simple tables/entities. Let&amp;#8217;s say we have to build a model for only one entity type, to store cars.&lt;/p&gt;

&lt;h3 id='car_entity_description'&gt;Car entity description&lt;/h3&gt;

&lt;p&gt;What fields should this entity have? Let them be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ID&lt;/code&gt; - the unique &lt;a href='http://msdn.microsoft.com/en-us/library/system.guid.aspx' title='Guid at MSDN'&gt;Guid&lt;/a&gt; of car record (primary key).&lt;/li&gt;

&lt;li&gt;&lt;code&gt;Name&lt;/code&gt; - car name string (if we need to specify the limit of this field, let it be maximum 80 chars).&lt;/li&gt;

&lt;li&gt;&lt;code&gt;YearOfAssembly&lt;/code&gt; - the year, when this car starts to drive (integer value).&lt;/li&gt;

&lt;li&gt;&lt;code&gt;Description&lt;/code&gt; - the text with notes about the car (infinite string).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id='car_entity_prototype_in_acrodb'&gt;Car entity prototype in AcroDb&lt;/h3&gt;

&lt;p&gt;Now let me describe, how this entity will look like in code using &lt;code&gt;AcroDb&lt;/code&gt; library.&lt;/p&gt;
&lt;div data-file='01.cs' class='gc' data-id='1960303'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And if you have setup &lt;code&gt;AcroDataContext&lt;/code&gt; class settings correctly as it was described in &lt;a href='/2010/03/20/acrodb-the-beginning/' title='AcroDB. The beginning'&gt;first post&lt;/a&gt;, after application start you will have a &lt;code&gt;Car&lt;/code&gt; table in your database/no-relational system. Or if you will change properties of this interface, table schema will be updated, thanks to &lt;code&gt;SubSonic&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So, &lt;code&gt;AcroColumnStringLength&lt;/code&gt; attribute is used to specify the maximum length of the column in db. The &lt;code&gt;AcroColumnStringLong&lt;/code&gt; attribute marks te column as infinite (MAX) size. For all column attributes, please, read &lt;a href='http://github.com/ioleksiy/AcroDB/blob/master/AcroDB/Attributes/ColumnAttributes.cs' title='Column attributes'&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id='working_with_entity'&gt;Working with entity&lt;/h2&gt;

&lt;p&gt;Now I will show the parts of code, how to work with our entity.&lt;/p&gt;

&lt;h3 id='creating_and_saving_an_object'&gt;Creating and saving an object&lt;/h3&gt;
&lt;div data-file='02.cs' class='gc' data-id='1960303'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id='querying_a_db'&gt;Querying a db&lt;/h3&gt;

&lt;p&gt;Here is a sample of Linq query for multiply objects:&lt;/p&gt;
&lt;div data-file='03.cs' class='gc' data-id='1960303'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Almost the same example for single object and count function:&lt;/p&gt;
&lt;div data-file='04.cs' class='gc' data-id='1960303'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, here you can use usual Linq methods applying to the &lt;code&gt;Query&lt;/code&gt; property, as &lt;code&gt;Query&lt;/code&gt; property is &lt;code&gt;IQueryabe&lt;/code&gt; type.&lt;/p&gt;

&lt;h3 id='updating_and_deleting_an_entity'&gt;Updating and deleting an entity&lt;/h3&gt;
&lt;div data-file='05.cs' class='gc' data-id='1960303'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id='the_end_for_today'&gt;The end for today&lt;/h2&gt;

&lt;p&gt;As you can see, I have tried to save the simplicity in working with objects as in &lt;code&gt;Linq2Sql&lt;/code&gt;, but have added a multi-context support for it, so you are not limited only for MS SQL&amp;#8230;&lt;/p&gt;

&lt;p&gt;Also, you don&amp;#8217;t need to work with db directly. All tables/objects will be created for you automatically.&lt;/p&gt;

&lt;p&gt;If you have any comments/proposals please, write them in comment form. Next time I plan to describe, how to use simple business logic layer with &lt;code&gt;AcroDb&lt;/code&gt; and relations between entities.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>AcroDB. The beginning</title>
   <link href="http://www.oleksiy.pro/2010/03/20/acrodb-the-beginning"/>
   <updated>2010-03-20T00:00:00-07:00</updated>
   <id>hhttp://www.oleksiy.pro/2010/03/20/acrodb-the-beginning</id>
   <content type="html">&lt;h2 id='the_big_day'&gt;The big day&lt;/h2&gt;

&lt;p&gt;After a year of hard work I begin to share new opesource projects with Internet community. Hope you will love it and use it in your development. Also, if someone will want to help me providing the future of this small creatures, please write me a line to email box.&lt;/p&gt;

&lt;h2 id='new_netbased_cms_the_content_management_system_that_is_free'&gt;New .Net-based CMS (the Content Management System) that is FREE&lt;/h2&gt;

&lt;p&gt;Ok, first of all about my ideas and projects. During last 3 years I was thinking of new stable and reliable &lt;code&gt;CMS&lt;/code&gt; system/framework that will be easy to work with for end users like websites owners, same as for developers. Please, don&amp;#8217;t think it is one more &lt;code&gt;CMS&lt;/code&gt; system, that is real shit&amp;#8230; Nope, we have given all love to this fantastic system, and all people who were testing it in internal testing, have already made good reviews about it.&lt;/p&gt;

&lt;h3 id='why_have_we_my_best_friend__designer_and_i_done_that'&gt;Why have we (my best friend - designer and I) done that?&lt;/h3&gt;

&lt;p&gt;While we were working at &lt;a href='http://www.acropolium.com/' title='Go to Acropolium Studio'&gt;Acropolium Studio&lt;/a&gt; since 2003, and our team already have done about 4-5 engines that were CMS-like systems. Some of them were plain, some of them - moduled and flexible, some - quick like a lightning. But all of those systems were developed on PHP. It is good technology and even now it has big popularity, but maybe because of my laziness, soon I have moved to C#. From the very beginning it was incredible language, same as .Net was a perfect technology.&lt;/p&gt;

&lt;p&gt;After some time developing and supporting web applications based on .Net framework, I have made a research on existent ASP.Net CMS systems. There were not a lot of them by that time. Also, almost all of them were shareware. That&amp;#8217;s why we have begin to think about new, fresh concepts in CMS building. And when the MVC.Net library appeared in RC1, I began to implement internal architecture of new, fresh, opensource cms. There were about four initial architecture implementations that have been gone to recycle bin. The only idea that have survived through last 2 years was the Data Access Layer provider (hope all of you are working with MVC pattern, so it was Model). And part of this layer that is separate thing now, I will describe today. Hope, other articles will appear once/twice per week.&lt;/p&gt;

&lt;h2 id='acrodb'&gt;AcroDB&lt;/h2&gt;

&lt;p&gt;The result you will see today is approximately 99% modified from the 2 years old version. 1% left the idea of the layer simplicity. About 60% of code were rewritten this week, after &lt;a href='http://web.archive.org/web/20101114001027/http://blog.wekeroad.com/2010/03/15/subsonic-migrations-without-subsonic' title='Migrations for .NET'&gt;SubSonic AutoMigrations&lt;/a&gt; appeared (many thanks to Rob Conery and Co). Before, it was the work of &lt;a href='http://msdn.microsoft.com/en-us/library/ms162169.aspx' title='Go to MSDN'&gt;Microsoft SMO&lt;/a&gt; - tons of code and same result as now (the only thing there were relations, but now we support no relation dbs and relations are not needed in simple data provider - one more &amp;#8220;hi&amp;#8221; to Rob&amp;#8217;s team for their &lt;code&gt;NoRM&lt;/code&gt;).&lt;/p&gt;

&lt;h3 id='the_goal'&gt;The goal&lt;/h3&gt;

&lt;p&gt;There are plenty tasks in developer life, where he need to make simple access to some data source quickly. For example, it is needed to make a temporary local list of visitors, or some cache in data source. What steps do developer needs to make to support this?:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select the data source provider, and if needed - install it.&lt;/li&gt;

&lt;li&gt;Create simple table structure to store data at later time.&lt;/li&gt;

&lt;li&gt;Create &lt;code&gt;ORM&lt;/code&gt; (we will work with linq2sql) prototype classes, that will work with this db.&lt;/li&gt;

&lt;li&gt;Create &lt;code&gt;Linq DataContext&lt;/code&gt; to work with source.&lt;/li&gt;

&lt;li&gt;Create simple data layer to access data through LINQ entities.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For harder projects this steps count could grow&amp;#8230; Also, if in future developer will need to change data source (for example move from &lt;code&gt;SQLite&lt;/code&gt; to &lt;code&gt;MS Sql&lt;/code&gt;), he will need to remake steps 2-4, and sometimes even step #5. Also, if we need to work with entity interfaces in project, than we will need to add step #2a to create prototype interfaces and change step #3 to inherit those interfaces by linq classes. If you will use &lt;code&gt;Nolics ORM&lt;/code&gt; you will need to write some more same text like prototype classes and interfaces&amp;#8230;&lt;/p&gt;

&lt;p&gt;So, what was the purpose of the AcroDB development? First of all to remove all non-needed steps and make them as internal work for DBProviderFactory. And as a result developer will got to write several lines to get access to rows in different DB system. Here is the list of tasks we have thought to achieve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Move abstraction of DB entity from classes to interfaces;&lt;/li&gt;

&lt;li&gt;Implement unique interface for add, edit, delete, query operations for any data provider (SQL db, No Relation DB, collection);&lt;/li&gt;

&lt;li&gt;Automatic tables creation/modifying (migration) in data provider, based on described entity interface (if it is SQL-oriented);&lt;/li&gt;

&lt;li&gt;Automated settings fetching from the loaded assemblies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I have wrote a lot of bad English text already, so let me put some code now:&lt;/p&gt;
&lt;div data-file='01.cs' class='gc' data-id='1960254'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is all things you need to do. Not very simple on first view, but you will not need to create something else to store data.&lt;/p&gt;

&lt;p&gt;So what we&amp;#8217;ve got here?&lt;/p&gt;

&lt;h3 id='acrodbentity_attribute'&gt;AcroDbEntity Attribute&lt;/h3&gt;

&lt;p&gt;This attribute applies to interfaces, to mark them for data context factory to be inherited at runtime. The line &lt;code&gt;AcroDataContext.ScanAssemblyForEntities&lt;/code&gt; calls a static method to scan assembly for interfaces marked with AcroDbEntity attribute. Than AcroDataContext makes a class that inherits this interface in memory using IL code generation. So, at the end, this class will be the endpoint for linq operations.&lt;/p&gt;

&lt;h3 id='datacontextfactory'&gt;DataContextFactory&lt;/h3&gt;

&lt;p&gt;It is an abstraction for any data context, which could be anything, like relations-based db, non-relation db, files, memory, etc. The only thing if you need to implement own data source context, you need to code 3 classes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;data provider (add,edit,delete,query commands implementation);&lt;/li&gt;

&lt;li&gt;data context (link to data source and transactions until commit changes);&lt;/li&gt;

&lt;li&gt;data source registrator - the class that will describe your&amp;#8217;s custom provider, and context (later we want to remove it and replace by attribute for data context).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;About implementing custom data source provider I will try to write an article asap.&lt;/p&gt;

&lt;h3 id='defaultdatacontext'&gt;DefaultDataContext&lt;/h3&gt;

&lt;p&gt;This static property of &lt;code&gt;AcroDataContext&lt;/code&gt; is determining the default datasource, with which the entities will work.&lt;/p&gt;

&lt;h3 id='acrodatacontextgo'&gt;AcroDataContext.Go&lt;/h3&gt;

&lt;p&gt;The helper method to create the instance of default data context to work with. Please, note, that data context implements &lt;code&gt;IDisposable&lt;/code&gt; to free all used resources quickly.&lt;/p&gt;

&lt;h3 id='working_with_entities'&gt;Working with entities&lt;/h3&gt;

&lt;p&gt;Inside using block you can see the creation of new object and it&amp;#8217;s storage to data source. While using the generic method of data context named &lt;code&gt;Provide&lt;/code&gt;, &lt;code&gt;AcroDB&lt;/code&gt; internally maps the interface to runtime created class and creates it&amp;#8217;s instance.&lt;/p&gt;

&lt;p&gt;As you can see at the end of using block, to ensure, that data was commited to data source, you need to call &lt;code&gt;SubmitChanges&lt;/code&gt; method like in simple LINQ context. It is not needed for all data source types, but to make system work with different providers, don&amp;#8217;t forget to call it.&lt;/p&gt;

&lt;h2 id='the_end_of_the_day_source_code'&gt;The end of the day. Source code&lt;/h2&gt;

&lt;p&gt;Thank you for reading this article. I will appreciate feedbacks and comments. If there were some not clear aspects of code, or text here, please comment about that. The source code of the library could be find at &lt;a href='http://github.com/ioleksiy/AcroDB' title='Go to Github'&gt;github&lt;/a&gt;. Don&amp;#8217;t forget to download &lt;a href='http://github.com/subsonic/SubSonic-3.0' title='Go to SubSonic Project'&gt;subsonic&lt;/a&gt; and &lt;a href='http://github.com/atheken/NoRM' title='Go to NoRM Project'&gt;NoRM&lt;/a&gt; (if you want to run mongodb provider) libs.&lt;/p&gt;

&lt;h3 id='ps_migration'&gt;P.S.: Migration&lt;/h3&gt;

&lt;p&gt;Almost forget about auto migration. Simply call &lt;em&gt;AcroDataContext.PerformMigrations()&lt;/em&gt; after loading all entities, to change datasource to latest entity description automatically. Once more thanks to Rob Conery.&lt;/p&gt;

&lt;p&gt;Also, there are a lot of internal sugar, that was not described here. But I will work on this, if it will be interesting.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>PHP Client for Java-based webservice</title>
   <link href="http://www.oleksiy.pro/2007/08/22/php-client-for-java-based-webservice"/>
   <updated>2007-08-22T00:00:00-07:00</updated>
   <id>hhttp://www.oleksiy.pro/2007/08/22/php-client-for-java-based-webservice</id>
   <content type="html">&lt;p&gt;While developing one commercial product I have met this problem, and for the research in it’s solvation have spent about 2-3 days. Maybe, this article will help some people, that are new to SOAP programming. So, If you will find it useful – I will be happy.&lt;/p&gt;

&lt;p&gt;Some time ago I have met a problem to connect the PHP script to Java-written webservice. It was a task, when the server-side part was developed as the collection of different webservices. For their good performance and memory on-fly caching support we have selected Java language and tomcat server as the main tools of development.&lt;/p&gt;

&lt;p&gt;On the other hand, a lot of already developed websites were written with the help of PHP language, because it is simple and powerful for small sites. Also, it is running good on the Linux/Unix platforms, which are much cheaper.&lt;/p&gt;

&lt;p&gt;So, we have to develop stubs (php classes that are giving access to remote webservice methods).&lt;/p&gt;

&lt;p&gt;By that time I have already worked with connections to the remote webservices using .Net Framework. There you need only to fill in the remote WSDL file path and Visual Studio will automatically generate stubs for you. So, there we even have no problems of cross-language remote connection.&lt;/p&gt;

&lt;p&gt;After developing all webservices that our company needed we have tested them with the help of small C#-written utility. As I have mentioned earlier – in VS (C#, .Net) there is no problem to create link to any webservice.&lt;/p&gt;

&lt;p&gt;The next task was to make PHP client to Java service. After some search in Google, have found that new version of PHP (version 5.0+) supports the SOAP connection as a client and as a server. Also, have found, that for the PHP version that is younger than 5th there was a library called NuSOAP (please, notice that this lib is not working with new versions of PHP).&lt;/p&gt;

&lt;p&gt;So, I have made an instance of SoapClient class in PHP and give it a WSDL URL as parameter. Than have tried to make some remote call&amp;#8230; Here the problem appears. The failure was with remote call parameters, just because Java webservice framework (JAXb, JAXr) converts simple collection of parameters to the one object with variables that are real parameters. Also, all argument names are renamed to the template &lt;code&gt;argX&lt;/code&gt;, where &lt;code&gt;X&lt;/code&gt; is a number of argument starting from 0.&lt;/p&gt;

&lt;p&gt;Also, there left some problem with passing &lt;code&gt;null&lt;/code&gt; value to remote call.&lt;/p&gt;

&lt;p&gt;For example, we have remote call to &lt;code&gt;Login&lt;/code&gt; method and it receives two parameters – username &amp;amp; password. So, the stub in PHP will be:&lt;/p&gt;
&lt;div data-file='01.php' class='gc' data-id='1959787'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In PHP code the remote call will be like this:&lt;/p&gt;
&lt;div data-file='02.php' class='gc' data-id='1959787'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Do you see how nice it is?&lt;/p&gt;

&lt;p&gt;Now, try to imagine, that this is only one remote call, and what will be if there are about 100 such calls? You will need 100 different stubs. Also, please, notice what will be the difference between these stubs. Let’s show one more example of more complicated call (&lt;code&gt;RegisterUser&lt;/code&gt;). Let’s imagine that there are such parameters – username, password, email, full name.&lt;/p&gt;

&lt;p&gt;So, the stub will be:&lt;/p&gt;
&lt;div data-file='03.php' class='gc' data-id='1959787'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And the code will be:&lt;/p&gt;
&lt;div data-file='04.php' class='gc' data-id='1959787'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Using the reflection technology, we can develop the class that will be as unique stub for all remote calls and it will dynamically create internal class variables for the arguments if needed. Here is the code of it:&lt;/p&gt;
&lt;div data-file='05.php' class='gc' data-id='1959787'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The example of call is here (for login stub):&lt;/p&gt;
&lt;div data-file='06.php' class='gc' data-id='1959787'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;That’s all. And the object will be filled with all needed &lt;code&gt;argX&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now, let’s unify the SoapClient class. All we need is to catch the call of external method with all parameters and dynamically create the stub and generate the remote call. Here is the code sample (please, note that here there is add-on information stored about logged in user session ID for future remote calls without passing this ID to the parameter list by developer):&lt;/p&gt;
&lt;div data-file='07.php' class='gc' data-id='1959787'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Not big part of code, but makes a lot of work for us. Now, let’s see how is it used:&lt;/p&gt;
&lt;div data-file='08.php' class='gc' data-id='1959787'&gt;
  &lt;pre&gt;Please, enable javascript, to see the source code.&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 
</feed>