tag:blogger.com,1999:blog-31929336196318289822024-03-18T21:13:26.084-07:00Pinoydev's eXpressMy personal collections of work, explorations and continuous learning experiences.Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.comBlogger22125tag:blogger.com,1999:blog-3192933619631828982.post-87965019369494840572012-11-20T18:10:00.000-08:002012-11-26T15:49:08.995-08:00Dynamically Load Form in MVC Razor View EngineOne part of my project gives user the ability to create forms and render it dynamically. Here's how I render the form definition from an XML container in Razor view engine.<br />
<br />
<b>The View</b><br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/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;"><code style="color: black; word-wrap: normal;"><span style="background: yellow;">@model </span>MyProject.Models.DynaForm
<span style="background: yellow;">@</span><span style="color: blue;">using</span> (Html.BeginForm(<span style="color: #a31515;">"ViewForm"</span>,<span style="color: #a31515;">"FormManagement"</span>, <span style="color: #2b91af;">FormMethod</span>.Post))
{
<span style="color: blue;">var</span> sectionCollection = <span style="color: blue;">from</span> s <span style="color: blue;">in</span> Model.XmlForm.Descendants(<span style="color: #a31515;">"section"</span>) <span style="color: blue;">select</span> s;
<span style="color: blue;">foreach</span>(System.Xml.Linq.XElement section <span style="color: blue;">in</span> sectionCollection) <span style="color: green;">// get sections</span>
{
<span style="color: blue;">var</span> fieldCollection = <span style="color: blue;">from</span> f <span style="color: blue;">in</span> section.Descendants(<span style="color: #a31515;">"field"</span>) <span style="color: blue;">select</span> f; <span style="color: green;">// get fields</span>
<span style="color: blue;"><</span><span style="color: maroon;">fieldset</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">legend</span><span style="color: blue;">></span>Section <span style="background: yellow;">@(</span>section.Attribute(<span style="color: #a31515;">"id"</span>).Value<span style="background: yellow;">)</span><span style="color: blue;"></</span><span style="color: maroon;">legend</span><span style="color: blue;">></span>
<span style="background: yellow;">@</span><span style="color: blue;">foreach</span> (System.Xml.Linq.XElement field <span style="color: blue;">in</span> fieldCollection) <span style="color: green;">// iterate over each field</span>
{
<span style="color: blue;"><</span><span style="color: maroon;">div</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">div</span><span style="color: blue;">></span><span style="background: yellow;">@</span>field.Attribute(<span style="color: #a31515;">"name"</span>).Value<span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">></span>
<span style="color: blue;"><</span><span style="color: maroon;">div</span><span style="color: blue;">></span><span style="background: yellow;">@</span>Html.TextBox(field.Attribute(<span style="color: #a31515;">"name"</span>).Value, field.Value, <span style="color: blue;">new</span> { @class = field.Attribute(<span style="color: #a31515;">"inputtype"</span>).Value }) <span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">></span>
}
<span style="color: blue;"></</span><span style="color: maroon;">fieldset</span><span style="color: blue;">></span>
}
<span style="color: blue;"><</span><span style="color: maroon;">input</span> <span style="color: red;">type</span><span style="color: blue;">=</span><span style="color: blue;">"submit"</span> <span style="color: red;">name</span><span style="color: blue;">=</span><span style="color: blue;">"submit"</span> <span style="color: red;">value</span><span style="color: blue;">=</span><span style="color: blue;">"save"</span> <span style="color: blue;">/></span>
<span style="color: blue;"><</span><span style="color: maroon;">input</span> <span style="color: red;">type</span><span style="color: blue;">=</span><span style="color: blue;">"submit"</span> <span style="color: red;">name</span><span style="color: blue;">=</span><span style="color: blue;">"submit"</span> <span style="color: red;">value</span><span style="color: blue;">=</span><span style="color: blue;">"cancel"</span> <span style="color: blue;">/></span>
}</code></code></pre>
<br />
<b>The Controller</b><br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/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;"><code style="color: black; word-wrap: normal;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ViewFormController</span> : <span style="color: #2b91af;">Controller</span>
{
Models.<span style="color: #2b91af; font-family: Consolas; font-size: 13px;">DynaForm</span> oWorkflow = <span style="color: blue; font-family: Consolas; font-size: 13px;">new</span> Models.<span style="color: #2b91af; font-family: Consolas; font-size: 13px;">DynaForm</span>();
<span style="color: blue;">public</span> <span style="color: #2b91af;">ActionResult</span> <span style="color: #2b91af; font-family: arial;">ViewForm</span><span style="font-family: arial;">()</span>
{
oDynaform.ID = 1;
oDynaform.XmlForm = <span style="color: #2b91af;">XDocument</span>.Load(Server.MapPath(<span style="color: #a31515;">"~/App_Data/myform.xml"</span>)); <span style="color: blue;">return</span> View(<span style="color: #a31515;">"ExecuteRequest"</span>, oWorkflow); <span style="color: green;">// pass this to view for rendering</span>
}
[<span style="color: #2b91af;">HttpPost</span>] <span style="color: green;">// POST handler</span>
<span style="color: blue;">public</span> <span style="color: #2b91af;">ActionResult</span> ViewForm(<span style="color: blue;">string</span> submit)
{
<span style="color: blue;">switch</span> (submit)
{
<span style="color: blue;">case</span> <span style="color: #a31515;">"save"</span>:
<span style="color: green;">// delegate sending to another controller action</span>
<span style="color: blue;">return</span> (Save());
<span style="color: blue;">case</span> <span style="color: #a31515;">"cancel"</span>:
<span style="color: green;">// call another action to perform the cancellation</span>
<span style="color: blue;">return</span> (CancelRequest());
<span style="color: blue;">default</span>:
<span style="color: green;">// If they've submitted the form without a submitButton, </span>
<span style="color: green;">// just return the view again.</span>
<span style="color: blue;">return</span> (View());
}
}
<span style="color: blue;">private</span> <span style="color: #2b91af;">ActionResult</span> CancelRequest()
{
<span style="color: blue;">return</span> (PartialView()); <span style="color: green;">// return to same page</span>
}
<span style="color: blue;">private</span> <span style="color: #2b91af;">ActionResult</span> Save()
{
oDynaForm.ID = 2;
<span style="color: blue;">return</span> (PartialView(<span style="color: #a31515;">"ViewForm"</span>, oDynaForm)); }
}</code></code></pre>
<br />
<br />
<br />
<b>The XML field template.</b><br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/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;"><code style="color: black; word-wrap: normal;"><span style="color: blue;"><</span><span style="color: #a31515;">dynamicform</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">yourform</span>"<span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">1</span>"<span style="color: blue;">></span>
<span style="color: blue;"> <</span><span style="color: #a31515;">section</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">1</span>"<span style="color: blue;">></span>
<span style="color: blue;"> <</span><span style="color: #a31515;">field</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">text</span>"<span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">First name</span>"<span style="color: blue;"> </span><span style="color: red;">inputtype</span><span style="color: blue;">=</span>"<span style="color: blue;">textbox</span>"<span style="color: blue;"> /></span>
<span style="color: blue;"> <</span><span style="color: #a31515;">field</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">text</span>"<span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Last name</span>"<span style="color: blue;"> </span><span style="color: red;">inputtype</span><span style="color: blue;">=</span>"<span style="color: blue;">textbox</span>"<span style="color: blue;"> /></span>
<span style="color: blue;"> <</span><span style="color: #a31515;">field</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">text</span>"<span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Email</span>"<span style="color: blue;"> </span><span style="color: red;">inputtype</span><span style="color: blue;">=</span>"<span style="color: blue;">textbox</span>"<span style="color: blue;"> /></span>
<span style="color: blue;"> </</span><span style="color: #a31515;">section</span><span style="color: blue;">></span>
<span style="color: blue;"> <</span><span style="color: #a31515;">section</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">2</span>"<span style="color: blue;">></span>
<span style="color: blue;"> <</span><span style="color: #a31515;">field</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">text</span>"<span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Other information</span>"<span style="color: blue;"> </span><span style="color: red;">inputtype</span><span style="color: blue;">=</span>"<span style="color: blue;">textarea</span>"<span style="color: blue;"> ></span> Other info here <span style="color: blue;"></</span><span style="color: #a31515;">field</span><span style="color: blue;">></span>
<span style="color: blue;"> </</span><span style="color: #a31515;">section</span><span style="color: blue;">></span>
<span style="color: blue;"> <</span><span style="color: #a31515;">section</span><span style="color: blue;"> </span><span style="color: red;">id</span><span style="color: blue;">=</span>"<span style="color: blue;">3</span>"<span style="color: blue;">></span>
<span style="color: blue;"> <</span><span style="color: #a31515;">field</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">text</span>"<span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Input 1</span>"<span style="color: blue;"> </span><span style="color: red;">inputtype</span><span style="color: blue;">=</span>"<span style="color: blue;">textarea</span>"<span style="color: blue;"> /></span>
<span style="color: blue;"> <</span><span style="color: #a31515;">field</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">text</span>"<span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Input 2</span>"<span style="color: blue;"> </span><span style="color: red;">inputtype</span><span style="color: blue;">=</span>"<span style="color: blue;">textarea</span>"<span style="color: blue;"> /></span>
<span style="color: blue;"> <</span><span style="color: #a31515;">field</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">text</span>"<span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Input 3</span>"<span style="color: blue;"> </span><span style="color: red;">inputtype</span><span style="color: blue;">=</span>"<span style="color: blue;">textarea</span>"<span style="color: blue;"> /></span>
<span style="color: blue;"> </</span><span style="color: #a31515;">section</span><span style="color: blue;">></span>
<span style="color: blue;"></</span><span style="color: #a31515;">dynamicform</span><span style="color: blue;">></span></code></code></pre>
Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-17106877441719459182012-11-06T15:52:00.001-08:002012-11-06T15:57:29.401-08:00Upgrading .NET Framework of IIS Application PoolYou've just installed your new website in IIS server but it doesn't seems to render correctly or throwing an error and pointing you to this line in web.config <br />
<br />
<code> <compilation debug="true" targetframework="4.0"><br />
</code><br />
<br />
Check your application pool, chances are, .NET Framework 4 is not yet installed. If your target framework is framework 2, then you can change that line to 2.0, as most IIS server default framework is using framework 2.0. Otherwise, you may need to install .NET framework 4. Follow that link to install (http://www.microsoft.com/net/download/version-4).<br />
<br />
After installation, run DOS in administrator mode, then dig to the specific framework directory and type the following (aspnet_regiis.exe -ir) as seen on this snapshot, to register and install it in IIS without affecting your IIS installation and current configuration.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/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;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmHTO5WF3h0fyrnmbaswpDf3QRV1j7EN2rGKI28iJG-5D3SW2xBsZj3CFHVG7vbm4duUh5aYSK1arKghDmrTfYdDM7UHs5cQaa5kXBHe2VNjLn_RkKB2In75I3ipCLsnEW9NwGs1OFsxw/s1600/Snap+2012-11-07+at+07.45.21.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/AVvXsEhmHTO5WF3h0fyrnmbaswpDf3QRV1j7EN2rGKI28iJG-5D3SW2xBsZj3CFHVG7vbm4duUh5aYSK1arKghDmrTfYdDM7UHs5cQaa5kXBHe2VNjLn_RkKB2In75I3ipCLsnEW9NwGs1OFsxw/s1600/Snap+2012-11-07+at+07.45.21.png" /></a>
</code></pre>
<br />
Open up your IIS manager, then change your website application pool to corresponding framework version. In this case, it's .NET Framework v4.0.30319.Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-16863189890963255552012-10-24T19:19:00.002-07:002012-10-25T02:02:10.583-07:00MVC and Entity Framework's Code FirstI have a new web application project and decided to use MVC 4 and Entity Framework's Code First. I'll post here the problems encountered and how I fixed it.<br />
<br />
MVC has option for automatic scaffolding when creating the CRUD functionality, but when I tried to execute it, I got the following error.<br />
<br />
Invalid value for key 'attachdbfilename'.<br />
<br />
I've searched the net for an hour and never found the solution. Though my connection string is working correctly, I decided to take a second look at the web.config and seen this peculiar line of setting. So I commented the LocalDBConnectionFactory and replaced with System.Data.Entity.Sql.ConnectionFactory instead so it will use the connection string on parameter. It fixed my problem.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/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;"><entityframework>
<defaultconnectionfactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<!--<defaultconnectionfactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" >-->
<parameters>
<parameter value="Data Source=USER-PC\SQLServer;Initial Catalog=MyDB;Integrated Security=True"></parameter>
</parameters>
</defaultconnectionfactory>
</entityframework>
</code></pre>
<br />
Entity Framework has this inherent problem whenever it needs to check Model changes, and it won't drop/create the target table, when you want to save. The following error, where 'dbContext' is your defined DB Context.<br />
<a name='more'></a><br />
<br />
The model backing the 'dbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).<br />
<br />
To solve this problem in CRUD, you need to add the following code on your corresponding controller constructor.<br />
<br />
Add this -> System.Data.Entity.Database.SetInitializer<dbcontext>(null);<br />
</dbcontext><br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/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 MyControllerController() : this(new MyModel())
{
System.Data.Entity.Database.SetInitializer<dbcontext>(null);
}
</dbcontext></code></pre>
<br />
Or if it's in a unit testing, add it under constructor, e.g.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/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;">
[TestClass]
public class UnitTestDB
{
public UnitTestDB()
{
System.Data.Entity.Database.SetInitializer<dbcontext>(null);
</dbcontext></code></pre>
Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-39498492387405477932012-07-26T01:54:00.001-07:002012-11-14T21:33:10.278-08:00Exploring LINQ<br />
During the old days of .net programming from framework 1.1 to framework 2.0, there's no LINQ library yet, so I established my skills on all sorts of different syntaxes for querying SQL, parsing XML Xpath, Object enumeration. But the demand for LINQ is unavoidable. This abstracted library for querying all sort of objects, be it SQL, dataset, XML, objects, arrays, etc. is quite handy because it allows you to query using a standard query syntax for all types of objects.<br />
<br />
The linq syntax is easier to practice using this tool called linqpad (www.linqpad.com). This allows you to execute queries from specified database and tables. For instance I want to...<br />
<br />
Read all data from table<br />
<blockquote class="tr_bq">
<code> from O in ORDERs select O </code></blockquote>
<br />
It has also support for reading only a portion and in the middle of table (similar to MySQL limit statement)<br />
<br />
<blockquote class="tr_bq">
<code> (from O in ORDERs select O).Skip(100).Take(50)</code></blockquote>
<br />
Joining two tables whose order id equals orderdetails id, and select firstname and the item from orderdetails.<br />
<br />
<blockquote class="tr_bq">
<code>from o in Orders join od in OrderDetails on o.ID equals od.OrderID select new {o.Firstname,od.Item}</code></blockquote>
<br />
Source: http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b<br />
<br />Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-63956199419050305442012-07-16T20:01:00.003-07:002012-09-22T06:28:33.764-07:00RAD Tools for Web App DevelopmentDuring my early years of programming in the 90s, every application needs to be coded manually and UI is text in appearance, programmers are limited to make UI out from combination of ASCII based characters. There are some attempts to make coding much simplier or at least much faster, one such RAD tool that exist is called Layout, it's the first WYSIWYG studio at that time, that could create true graphical UI and could run from DOS (has it's own graphics engine, and doesn't need windows OS).<br />
<br />
Layout was the first 4th generation language at that time. Imagine, you could create an application without a single coding effort, by just creating a flowchart and specifying the flow of the application by connecting lines to each and every box, each box represents a functionality, and the source code will be generated for you in either Basic, C++ or Pascal. This is similar to Windows Workflow Foundation of .NET framework, but less complicated. I created a simple app that I named Food Costing for storing/creating a list of recipies, and computes capital and retail cost in no time, even converted a Clipper based IT Applicant Exam in just 2 days. There was one another contender called Magic but these didn't last long.<br />
<br />
<a name='more'></a>These attempt to make programming much simplier and easier have never ceased to exist, as there's a need to balance a compromise between time and business need. The businesses needs applications to be up and running in no time. With todays technology, programming aspect have never matured, only the approach by adopting patterns of object oriented programming (or some coupled with aspect oriented programming) as compared to the traditional procedural programming (which still exist on all programming languages to support developers who have never embraced OOP yet). OOP is good as it hides the complexity of each functionality thru abstraction, but too much abstraction complicates OOP and adds overhead, in short it failed to address the need to create applications in no time.<br />
<br />
There are so many RAD tools available nowadays in the market to cut development time in half. One such tool worth mentioning is called CodeCharge Studio (from yessoftware.com), it generates code for you in PHP, ASP.NET - C#/VB, Perl, ColdFusion, Java/JSP, and supports majority of SQL database. One beauty of it is you can choose different theme/layout for different types of web applications, and if you're not happy, you can create theme from Artisteer (from artisteer.com) and use it instead.<br />
<br />
Half of the save time allows you to customize how pages fit together, you still have to code yourself but at least it saves you from common initial development effort of creating Datagrids CRUD, paging, menus and the like. It has ready made template/framework that would work out of the box for applications like Community Portal , Online Store, Task Management System, Employee Directory, Bug Tracker and Forum / Message Board.<br />
<br />
This is not a replacement for programmers/developers, but rather a tool to buy and save time.<br />
<br />Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-29687950194762895822012-07-12T02:50:00.001-07:002012-07-24T19:25:46.724-07:00How to Download JDK in CentOS / RHEL and Auto Accept License AgreementRecently as I was about to update a JDK on my Linux box (CentOS), the command wget couldn't get thru, it's receiving a 302 error. Browsing Oracle's download site, it has now a radio-button to accept / decline the License Agreement.<br />
<br />
Here's a workaround to bypass that. Issue the following command (make sure you replace the correct version of the JDK you're downloading).<br />
<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;">
wget --no-cookies --header "Cookie: gpw_e24=http%3A#2F#2Fwww.oracle.com" "http://download.oracle.com/otn-pub/java/jdk/7u5-b05/jdk-7u5-linux-x64.tar.gz"
</code></pre>Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-1384459229607342492012-07-12T02:14:00.002-07:002012-11-06T16:14:22.487-08:00Saving Objects for Later Debugging in .NETOne of the often challenge in debugging objects in .NET is the ability to start debugging in the middle of the running application, without the need to recreate all possible scenarios (be it data entry, API inputs ) just to arrive at the transformed data or derived object. This technique could also be used for requirements like persisting objects and saving it to database for later or whatever use.<br />
<br />
I've written a small utility that saves object to disk, and later load it back to the target object. This tool simply serializes object on save and deserialize it on load.<br />
<br />
Here's the snippet.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/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;">namespace Generics
{
public class Serializer<T><t>
{
public static T Load(string strPathFile)
{
T oBj = default(T);
System.Xml.Serialization.XmlSerializer objDeSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
System.IO.TextReader reader = new System.IO.StreamReader(strPathFile);
temp = (T)objDeSerializer.Deserialize(reader);
reader.Close();
return oBj;
}
public static void Save(string strPathFile, T oObject)
{
System.Xml.Serialization.XmlSerializer objSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
System.IO.TextWriter writer = new System.IO.StreamWriter(strPathFile);
objSerializer.Serialize(writer, oObject);
writer.Close();
}
}
}
</t></code></pre>
<br />
Make sure to put [Serializable] attribute on top of every class you want to get serialized.Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-10242623866539825842012-07-03T19:00:00.003-07:002012-10-29T17:41:30.213-07:00Node.js - Multithreaded Javascript EngineEver wondered how to implement multithreading in PHP? Natively, PHP can't do multithreading, only multiprocessing, but multiprocessing on a single resource in PHP is not robust solutions as it could encounter race condition, which is common problem in multithreading if the resource is not locked prior to being used. There are several techniques implementing multithreading in PHP but I'm only mentioning this particular lightweight framework. This is even simplier than ASP.NET inherent multithreading capabilities.<br />
<br />
Node.js (http://nodejs.org) is a javascript framework that could even act as a small web server. It allows you to implement multithreading without the hassle of locking/unlocking resources. It could even allow you to design stateful web (equivalent to viewstate/session management). It's even best for designing scalable clustered web app (where several instance resides on same multi-core servers or different servers with load balancer).<br />
<br />
<br />Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-87314150350836732652012-06-20T21:35:00.001-07:002012-07-12T02:55:22.723-07:00No Symbols Loaded - Debugging Silverlight App in ASPX PageI was once assigned to an ongoing silverlight project with Dynamic CRM integration with no technical documentation and was oriented only on the basics. Being an inquisitive person but couldn't get much help from the original team of developers (offshore), what I did was to examine the flow in debug mode. It's an expensive approach but leaves me no choice.<br />
<br />
<a name='more'></a>The project was done using MVC approach, consist of several projects, silverlight RIA and class libraries. The normal procedure of debugging by attaching several instances of iexplore.exe (being internet explorer as the default browser for testing) from the processes works fine, some symbols are loaded, but some are not. This is the same problem the original developer have faced and neither him has answer. I've searched for solutions but found none. I tried looking under Debug, Windows, Modules but the dependency library is nowhere to be found.<br />
<br />
The asp.net project, which is the main part of loading the silverlight project, was configured to use static port (right click on web project, select under properties window), and was predefined on IIS and gets published each time the project is rebuilt. I decided to break this pattern by loading the asp.net page from within visual studio (instead of directly invoking it thru internet explorer and attaching to process), but first (1) stop the web application in IIS, (2) then right click on the asp.net project and set it as the startup project, and (3) click debug, voila!, all symbols are loaded.<br />
<br />
<br />
<br />
<br />
<br />
<br />Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-79876592870544200492012-06-13T00:52:00.002-07:002012-07-12T02:55:57.667-07:00Fixing Too Many Connection ProblemMy very first .Net project way back in year 2003 using Visual Studio 2003 (later switch to 2005, 2008 and 2010 as time went by), and using MySQL 4.1 (later migrated to MySQL 5.5) as the backend database, was faced with the same database connectivity problem, the application often would encounter this "Too many connection.." error, when the database driver (MySQL.NET), after some prolong running, could not established database connection anymore.<br />
<br />
I've fixed this by inserting the following code under the try/catch database connectivity error handler.<br />
<blockquote class="tr_bq">
<code>
System.Data.SqlClient.SqlConnection.ClearAllPools();</code></blockquote>
The same line of code works in .NET default data driver ADO.NET hence MySQL.Net driver has adopted ADO.NET namespace for ease of using either SQL Server or MySQL database.<br />
<br />
The nature of my application is multithreaded and demands for very fast database connection as each task per user has to spin each own background thread from the threadpool. But if your application is not very particular about database connection speed and would like each instance being destroyed immediately after closing the database connector, you can adjust it on IIS application settings or via the connection string by setting Pooling=false.Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-30006415848527413782012-06-12T19:53:00.002-07:002012-07-12T02:56:18.877-07:00Reading Cookie from Other Website with Different DomainBy W3C rule, a web browser is not permitted to read cookies from different site with different domains. So how do we beat the challenge of reading cookies from other 3rd party site when let's say you were task to integrate it in your site and there are some needed parameters that are stored on 3rd party cookies which you need to read.<br />
<br />
You'll need your Network Admin guy for this task or if you have access to CPanel or similar UI which allows your to assign subdomain alias (CNAME). <br />
<br />
<a name='more'></a>First, create a subdomain definition from your own domain, let's say var.mydomain.com. Then add the alias for the target domain/subdomain (e.g. www.analytics.com) to equate/resolve to your subdomain (in this case, var.mydomain.com). Just to avoid legality issues, you may ask permission from the 3rd party site that you want to create alias for their domain for purpose of integrating and allowing your site to read their cookie .<br />
<br />
Now here's the magic, when you invoke the 3rd party site from within your site, e.g. from a particular URL (http://www.analytics.com/trackvisit.php), and that site started writing cookie. That cookie will be saved under var.mydomain.com which is your defined subdomain. Any subdomain under your domain allows browser to read that cookie from your site.<br />
<br />
With this technique, you can also implement any session sharing imaginable, e.g. Single login from different disperse site, provided you owned and have access to the site's source code.Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-22578793831970109302012-06-12T19:16:00.002-07:002012-07-12T02:56:34.563-07:00Single Login Session Between WebsitesSingle sign-on or login allows user to login from one site or another and authentication happens only once per active session. Without this mechanism, it would be annoying to the user whenever he wants to switch between website and prompted again to login.<br />
<br />
In ASP.NET, to implement single sign-on or login between websites on same domain with different subdomain, do the following:<br />
<br />
<a name='more'></a><br />
<br />
In the web.config of both projects, change the authentication node to this:<br />
<blockquote class="tr_bq">
<code><authentication mode="Forms">
<forms name="SampleAuth" loginUrl="/TestWebApp2/Test.aspx" slidingExpiration="true" />
</authentication> </code></blockquote>
Change the loginUrl to be that of your login page. Then change the authorization node in the web.config to be this:<br />
<blockquote class="tr_bq">
<code><authorization>
<deny users="?" />
</authorization> </code></blockquote>
In your login page code, when you've authenticated the user, do this:<br />
<blockquote class="tr_bq">
<code>System.Web.Security.FormsAuthentication.RedirectFromLoginPage("Jun", true); </code></blockquote>
Now, in your other web application (Webapp2 for example), you can get at the<br />
username ("Jun" in this case), by using:<br />
<blockquote class="tr_bq">
<code>System.Web.HttpContext.Current.User.Identity.Name </code></blockquote>
You'll also need to change the machinekey node in your machine.config (on both website), specifying not generate different keys for different apps. Change it to something like this:<br />
<blockquote class="tr_bq">
<code><machineKey validationKey="35735679267934518456825687653568905 6434617489465"
decryptionKey="35735679267934518456825687653568905 6434617489465"
validation="SHA1"/> </code></blockquote>
You need to provide your own values for the machine keys. There are some tools that can generate keys for you,<a href="http://www.codeproject.com/Articles/16645/ASP-NET-machineKey-Generator" target="_blank"> click here</a> to launch the key generator made by one of codeproject contributor.Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-12870780020853462812012-06-06T19:23:00.001-07:002012-06-07T18:18:17.440-07:00Where to Upload and Host CSS / Javascript - Fast and FreeThere are a lot of free site that offers to host your script for free yet some have limited bandwidth and slow. But there's one without bandwidth limit and very fast, yet the feature is not obvious for hosting CSS and JAVA script.<br />
<br />
Google has a lot of useful yet free applications, and one of that is Google Docs. It's a collaborative office applications where it allows you to do document editing online., but we're not going to use that feature, rather to host script file.<br />
<br />
<a name='more'></a>Yes, we're going to use Google Docs, this time to host your script. Basically, it allows you to upload any document, and all files are technically a document.<br />
<br />
Login to your google account and select google docs, then click Upload.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1wKAp7YAukcv9tHT8Asl8w_USLUnTSMTxqFk__xGwiuVmu0zZDNHOy94wEhNy6elI9cztvE7kmzH3RnjgjEExsY2GnrlOj7haBpIumRvGGQq-mMtsT-OPOqiuhXjAGrLa7PDpmOjDwBQ/s1600/googledocs.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1wKAp7YAukcv9tHT8Asl8w_USLUnTSMTxqFk__xGwiuVmu0zZDNHOy94wEhNy6elI9cztvE7kmzH3RnjgjEExsY2GnrlOj7haBpIumRvGGQq-mMtsT-OPOqiuhXjAGrLa7PDpmOjDwBQ/s1600/googledocs.jpg" style="border: 1px solid burlywood;" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Follow the red highlight in sequence.<br />
<ul>
<li>Select files to upload (your script file, with whatever file type or extension)</li>
<li>Uncheck the Convert document ....</li>
<li>Select Anyone with the link or public</li>
<li>Finally, click Start Upload</li>
</ul>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh5LDh4mgF4qfFPSP-4P_7TuIj9P5TzeQAhHjQ9hHXElZaDSasehlgVmFG8d1hzYZjafID16Y9vBoHTuwTdT4TqNqUXmg3UknNVn_0wM_70auj7jQt9uutq-S1Cui7nrI9Uehu9kZbKV0/s1600/googledoc2.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh5LDh4mgF4qfFPSP-4P_7TuIj9P5TzeQAhHjQ9hHXElZaDSasehlgVmFG8d1hzYZjafID16Y9vBoHTuwTdT4TqNqUXmg3UknNVn_0wM_70auj7jQt9uutq-S1Cui7nrI9Uehu9kZbKV0/s1600/googledoc2.jpg" style="border: 1px solid burlywood;" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Assuming the file you uploaded was named panel.css. Now right click on Open, and select Copy Link Location.<br />
<br />
<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZobCyRZ9GuYn_ScsYKR01pPk8Iaf53BFxcq3PMkVKPFh71rYRwsgQQKu_p5cQm3YPhvRNPPIjYjn4jXmMvdQP_K1U16kPQ21krjrpmsPSMP1Am2S5EwSnAo-sth4yZ1WDtwV5HbRy674/s1600/googledoc3.jpg" style="border: 1px solid burlywood;" /><br />
<br />
Presto, you've successfully uploaded your script, and now you can use that copied URL as your source of your javascript or css.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6pg3r4rxJmHhyphenhypheneMawgUovyG-SCiUZCNI7q1VMQfsN-oeox2EMUV7AB_1P6BwVAH1hJRNbM3vEUEkWuiqmAyshO8VPGcl9d9mdt3jemTJsW4uSFh2APCmOeEqUtAX-BDyqLNUIVVUY7uw/s1600/googledoc4.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6pg3r4rxJmHhyphenhypheneMawgUovyG-SCiUZCNI7q1VMQfsN-oeox2EMUV7AB_1P6BwVAH1hJRNbM3vEUEkWuiqmAyshO8VPGcl9d9mdt3jemTJsW4uSFh2APCmOeEqUtAX-BDyqLNUIVVUY7uw/s1600/googledoc4.jpg" style="border: 1px solid burlywood;" /></a></div>Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-58121663665566813252012-06-06T02:37:00.001-07:002012-07-24T19:27:27.222-07:00MS Access Export to Excel or CSVExporting data from Ms Access 2007 to Excel from code is just a one line statement using <code>DoCmd.TransferSpreadsheet</code>, but in CSV there's an inherent bug so I created my own export module. Plus a special function that saves file to disk, which I modified a bit to make it work on 64 bit machine.<br />
<br />
<a href="http://2.bp.blogspot.com/-_Ht90UEKI-o/T88fNdcWQnI/AAAAAAAAAH0/UJ3nbjtbl7k/s538/export2.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-_Ht90UEKI-o/T88fNdcWQnI/AAAAAAAAAH0/UJ3nbjtbl7k/s1600/export2.jpg" /></a><span id="goog_1698885028"><br />
</span><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<a name='more'></a><br />
<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;">
Private Sub cmdExport_Click()
On Error GoTo ShowError
Dim strFilter As String
Dim strFilename As String
'Ask for SaveFileName
Select Case optFileType.value
Case 1
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", "*.xls")
Case 2
strFilter = ahtAddFilterItem(strFilter, "CSV Files (*.csv)", "*.csv")
End Select
strFilename = ahtCommonFileOpenSave(OpenFile:=False, _
Filter:=strFilter, _
Flags:=ahtOFN_OVERWRITEPROMPT Or ahtOFN_READONLY, _
FileName:="Export as of " & Format(Now, "mm-dd-yyyy hh-MM AMPM"))
If Len(Trim(strFilename)) > 0 Then
Select Case optFileType.value
Case 1
Select Case cboExcelVersion.ListIndex
Case 0 '2007
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "ExportDescriptive", strFilename
Case 1 '2000
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "ExportDescriptive", strFilename
Case 2 '97
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "ExportDescriptive", strFilename
Case 3 '95
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "ExportDescriptive", strFilename
End Select
MsgBox "Data has been exported successfully to excel", vbInformation
Case 2
'this has bug, so not using this
'DoCmd.TransferText acExportDelim, "SaveCSV", "ExportDescriptive", strFilename, True
'use this instead
Export2CSV strFilename & ".csv", ","
End Select
MsgBox "Records exported", vbInformation
End If
GoTo NoError
ShowError:
MsgBox Error
NoError:
End Sub</code></pre><br />
As you can see from the code, I commented out the <code>DoCmd.TransferText</code> and replaced it with The Export2CSV customized function. Here's the code.<br />
<br />
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOteSec1ZpPqU0i4pORV2S6OX3Ewbq2uHR7qww7Hy5E1KcvNVf_HeQNe9bmKEYzs49e4N78XRZdi8uL-7DzFWIGSKj7Kdns3eX__NYg1lK5dfuPReKuKO0CXhJxJVZSFKAc8AgPIv4C6X4/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;">
Option Explicit
Public Sub Export2CSV(strFilename, strDelimiter)
On Error GoTo ShowError
Dim dbItem As Database
Dim rsExport As DAO.Recordset
Dim strCol As String
Dim strTemp As String
Set dbItem = CurrentDb
Set rsExport = dbItem.OpenRecordset("ExportDescriptive")
Dim nRow As Long
Dim nCol As Long
Open strFilename For Output As #1
strCol = "" 'print headers
For nCol = 1 To rsExport.Fields.Count - 1
strTemp = rsExport.Fields(nCol - 1).Name
If nCol < rsExport.Fields.Count Then
strCol = strCol & strTemp & strDelimiter
End If
Next nCol
Write #1, strCol & vbCrLf
If rsExport.RecordCount > 0 Then
rsExport.MoveLast
rsExport.MoveFirst
'nRow = 0
Do While Not rsExport.EOF
'For nRow = 1 To rsExport.RecordCount
'nRow = nRow + 1
strCol = ""
For nCol = 1 To rsExport.Fields.Count - 1
strTemp = IIf(IsNull(rsExport.Fields(nCol - 1).value), "", rsExport.Fields(nCol - 1).value)
If strDelimiter = vbTab Then
strTemp = Replace(strTemp, vbTab, "")
End If
strTemp = Replace(strTemp, Chr(34), Chr(34) & Chr(34)) 'find double quote and escape it with double quote
If strDelimiter <> vbTab Then 'if delimiter is other than tab
If InStr(1, strTemp, strDelimiter) > 0 Then
strTemp = Chr(34) & strTemp & Chr(34) ' enclosed in double quote, as entire text qualifier
End If
End If
strCol = strCol + strTemp
If nCol < rsExport.Fields.Count Then
strCol = strCol & strDelimiter
End If
Next nCol
Write #1, strCol & vbCrLf
rsExport.MoveNext
Loop 'Next nRow
End If
Close #1
rsExport.Close
GoTo Bypass
ShowError:
MsgBox Error, vbCritical
Bypass:
Set dbItem = Nothing
Set rsExport = Nothing
End Sub
</code></pre><br />
And lastly the customized function for saving the CSV file to disk. It's quite a long script so I'll just provide here the link to that, <a href="https://docs.google.com/open?id=0B7EVHKuvpFiDMktCLWZWVWhtMFk" target="_blank">click here to view</a>.<br />
<br />
<br />Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-23884704312970663072012-06-06T01:45:00.000-07:002012-06-13T00:17:13.708-07:00Deploying CRM 4 Database Instance to Another ServerOur IT admin was once task to deploy an existing CRM 4 instance to another server for development purposes and he sought my help.<br />
<br />
It's assume you have prior knowledge of SQL Server Management Studio, then do the following:<br />
1) Backup the CRM database.<br />
2) Install Microsoft SQL Server 2005 or 2008 on a new server<br />
2.a)- make sure SSRS feature checkbox is checked, this reporting services is required by CRM.<br />
3) Install Dynamic CRM 4 to that same server.<br />
4) Restore CRM database.<br />
<br />
<a name='more'></a><br />
<br />
Now here's the detailed part on CRM 4 installation.<br />
<br />
5) Open Deployment Manager (under All Programs/Dynamic CRM 4)<br />
6) Right click Organizations, click Import Organization (click Yes when prompted).<br />
7) On SQL Server box, type the name of the SQL server instance.<br />
7.a) Select the organization database in the Organization database box and click Next.<br />
8) Type the display name and the name for the organization, and then click Next.<br />
9) Type the URL in the SQL Server Reporting Services URL box, and then click Next.<br />
- You can find the URL from the Report Services Configuration Manager, under Web Service URL (don't confuse with Report Manager URL).<br />
10) Select the method in the Method for the Mapping of the Users list, and then click Next.<br />
- In our case we have no existing mapping of users from clients, so I just selected Manual Mapping, and pick one particular user and mapped it to one of the computer user, e.g. administrator.<br />
10.a) Map the users, and then click Next.<br />
11) Click Import.<br />
<br />
Now you can test your newly deployed CRM 4 database, open IIS and select Microsoft Dynamics CRM and select browse site. Enter now the username (in our case administrator), and corresponding password, and you're all set.<br />
<br />
<br />
<br />
<br />
<br />Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-40145683868170114542011-09-13T20:44:00.000-07:002012-05-30T23:02:02.318-07:00Rapid UI Wireframe Prototyping with Evolus PencilIn desktop or web application development, some users could effectively narrate how they want the application's UI usability would look like, but some requires to see a glimpse of a UI prototype before they could finally agree at least initially to the laid out UI. There are variety of tools to do this, and there's one tool that became one of my favorite named Evolus Pencil (http://pencil.evolus.vn/en-US/Home.aspx). Ironic that it was built on Javascript but the homepage was created in asp.net.<br />
<br />
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhq1e04e3iNXzapRx75o8gQZlfHTsx8R5TDPDw3Y-HbEDE5xacdpX8QxnrGe36t2nZc76yuT3JVqtjZIQHfMwIM9d4ckABi89GdEnGw-5SqjQF4PJW-YG_kXatGQlrTttLj6XPvmmLYyU/s1600/pencil1.jpg" imageanchor="1" style="margin-left: 0em; margin-right: 0em;"><img border="0" height="380" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhq1e04e3iNXzapRx75o8gQZlfHTsx8R5TDPDw3Y-HbEDE5xacdpX8QxnrGe36t2nZc76yuT3JVqtjZIQHfMwIM9d4ckABi89GdEnGw-5SqjQF4PJW-YG_kXatGQlrTttLj6XPvmmLYyU/s640/pencil1.jpg" width="600" /></a></div>
<br />
Evolus' Pencil allows you to create rapid UI prototype. The simplicity of this tool is what caught me and the sketchy appearance, which mimic the appearance of hand-drawn UI. This could also be used to prototype flowchart, or even touchscreen/pad apps.<br />
<br />
There are many UI wireframe prototyping available, some even are interactive but I have covered only this one, being used most often.Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-69377049925764696462011-09-13T19:14:00.000-07:002011-09-13T19:15:02.808-07:00ReactOS a free OS replacement for Windows XP/2003Aside from the corporate world, if there's any other reason why I'm sticking to Windows OS, is that most of my best favorite games on PC runs on Windows, and neither I would sacrifice game performance thru the use of emulators just to run games in other OS.<br />
<br />
If only all game developers have supported OpenGL, users would have a variety of OS to run games, but then it seems DirectX has dominated as the graphics API of choice for game development, it's because it forces developers to choose it, to support newer releases of Windows OS. DirectX 11 will only run under Windows Vista, 7 and 8.<br />
<br />
This is the sad part, goodbye to DirectX 10 which would only run under Windows XP/ME edition. If you have newer games that only could run under DirectX 11, you are obliged to upgrade your Windows OS as well.<br />
<br />
But wait, there are bunch of geeks developing a so called ReactOS (www.reactos.org), a substitute to Windows dominance, it's neither Linux or other emulated OS. It's a Windows OS built based on Windows XP and Windows 2003 architecture. It aims to support all Windows Applications that runs on previous version of Windows, including the support for DirectX of any version. Hopefully it will succeed if we users support it.<br />
<br />
Spread the word!Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-69475522930391515192011-08-16T01:01:00.000-07:002012-05-30T23:18:13.446-07:00Hiding Footer, Navigation Bar, Logo - Customizing BlogpostSometimes you want greater control over a ready made template in blogspot for personal choice. Here's a compiled tip how you could customize and override it by using the power of CSS. There are some other non CSS hack like commenting out some code but sometimes it becomes non-workable so I've choosen only CSS technique as it seamlessly work across different browsers.<br />
<br />
Before you go any further, it's best to copy and paste your blogspot html in a notepad editor, this is to avoid accidental messing of template/html, in my case I use notepad++, then do the code change from there, and copy/paste the entire content from notepad back to blogspot html editor.<br />
<br />
Edit your blog HTML (under template, click edit template/html) and insert the following line of code on the template, just right above this excerpt of code <b><i>"/* Variable definitions ... "</i></b><br />
<br />
<a name='more'></a><br />
<br />
Hide the navigation bar, add ...<br />
<blockquote>
#navbar-iframe {display: none;}</blockquote>
Hide the footer, add ...<br />
<blockquote>
#Attribution1 {display:none;}</blockquote>
Hide the subscribe to (Atom) feed link, add ...<br />
<blockquote>
.feed-links {display:none;} </blockquote>
And now to customize the URL logo, find the following code<br />
<pre><b:include data="blog" name="all-head-content">
</pre>
then replace the image URL with your own logo, corresponding to wherever URL it is hosted. <br />
<pre><link href="http://ur.img.com/guides.png" rel="shortcut icon" type="image/png"></pre>
don't forget to change the corresponding image type, e.g. image/gif, in this case it's png type.<br />
<br />Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-53169025732456337242011-08-06T07:47:00.000-07:002012-06-27T22:36:21.218-07:00Don't Judge Linux by its CoverDuring my college years in the 90s, we were taught all about DOS (Disk Operating System). Typing commands from the console is fun, and I even love doing batch programming, but then Windows came and it appealed to many, because of its intuitive user interface. No doubt, Windows dominated the personal computers, and most of my programming careers were centered on Windows OS.<br />
<br />
Recently Linux is fast becoming one of the well known OS, though it appealed mostly to techno savy users because it has no intuitive interface pleasing to the general public. It's just like DOS where you have to type every command at the console. It didn't caught much of the common users attention until a friendly GUI or Windows like interface have proliferated like Ubuntu, and CentOS to name a few.<br />
<br />
<a name='more'></a>Actually I'm one of those that didn't like Linux because I thought, why should I get back to typing long series of every commands which is tiresome, when a simple click of a button would do in a GUI oriented OS. But then recently, I was given a project and got the chance to use CentOS (Red Hat origin) on a 64 bit machine, and I started to admire it. Though most of the task at hand which requires administrative know-how is still best executed thru the terminal. Which, ironically, I started to love again typing every commands just like the old days of DOS. Well I guess, it's part of the excitement of learning and I didn't even find any steep learning curve for Linux. Thanks to its similarities with DOS architecture on how the Linux OS organizes everything like the users, devices, folders, etc. with a few but minor differences.<br />
<br />
In just short period of time I manages to learn systems administration, especially on applications like Apache/Nginx and MySQL (which I happen to use also on Windows). Excitingly, there's so much applications to choose from that are freely available. The motivation of learning was driven by a given task/project, coupled with self motivation, it is the easiest and fun way of learning linux. I continued exploring and learning Linux thru Virtualbox, installation is no feat, it feels like doing a Windows installation.<br />
<br />
Indeed, Linux is one of the best OS ever created, and is not far from becoming the leading and favorite OS among common users. So those who haven't yet tried or still reluctant to get there feet wet on Linux, don't be afraid, the water is cold only at first, but it gets comfortable soon after. I'm a new convert but of course neither I'm leaving Windows OS for I have built my entire career on it, rather I'm embracing both OS.<br />
<br />
Ready to explore? Don't forget though, Linux is case sensitive, it doesn't know that "I" and "i" are just the same (no pun intended).Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-51433667204654297892011-06-16T20:06:00.000-07:002012-06-25T19:39:17.244-07:00Reverse Proxy Using Nginx to Serve Static Files Faster<b>Reverse Proxy</b><br />
A proxy in common usage, is a stand-in for a web-browser. When a web browser requests access to a web resource, the web resource needs some idea of where it should send the answer. In reverse, the proxy stands-in for the web server. In such a case, the true location of the web server (whose content is being served) is hidden, from the standpoint of the client making the request. <br />
<br />
The common solutions found on web is to point all traffic to NGINX and route traffic to APACHE if it's not static files, but with our case, we don't want to change the current configuration of existing APACHE installation and settings as much as possible. The safe technique will be used to serve static contents like images from another server using a much lighter web server application name NGINX. The rest of the page would remain served via APACHE.<br />
<br />
I've done this prototype in 64 Bit Red Hat Linux, some command may vary in other Linux distro.<br />
<a name='more'></a><br />
<b>Configuration</b>
<br />
<br />
<b>Host File</b><br />
On client PC, add the following to hosts file so the virtual DNS could be resolved unto that IP to which corresponds to the IP of the server.<br />
<br />
<ul>
<li>10.10.25.140 jun.images.com </li>
<li>10.10.25.140 jun.homepage.com </li>
</ul>
<br />
<b>Port</b>
<br />
Since this Proof of Concept will be hosted on same server, we would retain the current port 80 for APACHE, while for NGINX we could choose other ports e.g. 8000, 8888 or anything within that range whichever is available. Assigning which port will be covered under VHOST. <br />
<br />
<b>Vhost</b>
<br />
Let's create a vhost in Apache under /etc/httpd/conf.d/vhosts named jun.homepage.vhost , it should contain the following code:<br />
<br />
<pre><code> <virtualhost *:80="">
DocumentRoot "/var/www/html/sites/jun.homepage.com"
ServerName jun.homepage.com
<directory "="" html="" jun.homepage.com"="" sites="" var="" www="">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</directory>
RewriteEngine On
#RewriteLog "/var/log/httpd/rewrite.log"
#RewriteLogLevel 9
RewriteRule ^/(.*\.(js|css|rdf|xml|ico|txt|gif|jpg|png|jpeg)) http://127.0.0.1:8888/$1 [P,L]
</virtualhost></code></pre>
<br />
As can be seen on the rewrite rule, any static content will be passed thru a specified URL (localhost in this case). <br />
<br />
<br />
And for Nginx under /etc/nginx <br />
<ul>
<li>Edit nginx.conf and include this line <b>include /etc/nginx/conf.d/vhosts/*.vhost; </b> at the bottom (before }) </li>
<li>Create file under /etc/nginx/conf.d/vhosts, and name it jun.images.vhost , containing the following code:
<pre><code>server {
listen 8888;
server_name jun.images.com;
location / { root /var/www/html/sites/jun.images.com/;
index index.html;
}
}</code></pre>
</li>
</ul>
Here we have specified Nginx to listen on port 8888, and the URL of server name. Under <b>Location</b>, this is where all static contents should be placed at the specified directory. <br />
<br />
<br />
<b>Sample Page</b>
<br />
<ul>
<li>Place a sample image under <b>/var/www/html/sites/jun.images.com/</b> name test1.jpg </li>
<li>Create an index.html under <b>/var/www/html/sites/jun.homepage.com</b> with the following code:</li>
<pre><code>
<html>
<head>
<title>Image Pass-Thru POC</title>
</head>
<body>
<img width="20%" height="20%" src="http://jun.homepage.com/test1.jpg" />
</body>
</html>
</code></pre>
</ul>
On this page (http://jun.homepage.com/index.html - take note that this is only local and may not be accessible elsewhere, you must substitute your own site to which you wish to simulate the test), we are referencing images as is but under the hood, the rewrite rule in apache would convert the current URL to another URL as pass-thru, meaning on the surface, user won't see any changes in terms of image URL.<br />
<br />
<b>Benchmark Results</b>
<br />
<br />
With Reverse Proxy enabled, (second test on same setup is a repost which could use OS/hardware cache in the process)<br />
<br />
<pre><code>ab -n 100 -c 100 http://jun.homepage.com/index.html
Benchmarking jun.homepage.com (be patient).....done
Server Software: Apache/2.2.8
Server Hostname: jun.homepage.com
Server Port: 80
Document Path: /index.html
Document Length: 326 bytes
Concurrency Level: 100
Time taken for tests: 0.19610 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 59500 bytes
HTML transferred: 32600 bytes
Requests per second: 5099.44 [#/sec] (mean)
Time per request: 19.610 [ms] (mean)
Time per request: 0.196 [ms] (mean, across all concurrent requests)
Transfer rate: 2957.67 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 4 2.8 5 9
Processing: 3 6 2.2 7 10
Waiting: 2 6 2.1 6 9
Total: 3 11 4.8 12 19
Percentage of the requests served within a certain time (ms)
50% 12
66% 14
75% 15
80% 16
90% 18
95% 18
98% 19
99% 19
100% 19 (longest request)
Repost:
Server Software: Apache/2.2.8
Server Hostname: jun.homepage.com
Server Port: 80
Document Path: /index.html
Document Length: 326 bytes
Concurrency Level: 100
Time taken for tests: 0.16391 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 59500 bytes
HTML transferred: 32600 bytes
Requests per second: 6100.91 [#/sec] (mean)
Time per request: 16.391 [ms] (mean)
Time per request: 0.164 [ms] (mean, across all concurrent requests)
Transfer rate: 3538.53 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 2.2 3 7
Processing: 3 6 1.9 6 9
Waiting: 2 5 1.9 6 8
Total: 3 9 3.9 10 16
Percentage of the requests served within a certain time (ms)
50% 10
66% 12
75% 13
80% 14
90% 15
95% 15
98% 15
99% 16
100% 16 (longest request)</code></pre>
<br />
<br />
<br />
And the result having served all contents in Apache (second test on same setup, is a repost which could use OS/hardware cache in the process) <br />
<pre><code>ab -n 100 -c 100 http://jun.homepage.com/index.html
Benchmarking jun.homepage.com (be patient).....done
Server Software: Apache/2.2.8
Server Hostname: jun.homepage.com
Server Port: 80
Document Path: /index.html
Document Length: 326 bytes
Concurrency Level: 100
Time taken for tests: 0.27270 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 59500 bytes
HTML transferred: 32600 bytes
Requests per second: 3667.03 [#/sec] (mean)
Time per request: 27.270 [ms] (mean)
Time per request: 0.273 [ms] (mean, across all concurrent requests)
Transfer rate: 2126.88 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 5 3.3 5 10
Processing: 4 13 3.0 14 17
Waiting: 3 12 3.2 13 16
Total: 4 18 5.7 20 27
Percentage of the requests served within a certain time (ms)
50% 20
66% 22
75% 23
80% 24
90% 25
95% 26
98% 26
99% 27
100% 27 (longest request)
Repost:
Server Software: Apache/2.2.8
Server Hostname: jun.homepage.com
Server Port: 80
Document Path: /index.html
Document Length: 326 bytes
Concurrency Level: 100
Time taken for tests: 0.18472 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 59500 bytes
HTML transferred: 32600 bytes
Requests per second: 5413.60 [#/sec] (mean)
Time per request: 18.472 [ms] (mean)
Time per request: 0.185 [ms] (mean, across all concurrent requests)
Transfer rate: 3139.89 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 2.5 4 8
Processing: 3 6 2.3 6 10
Waiting: 2 5 2.5 6 9
Total: 3 10 4.6 10 18
Percentage of the requests served within a certain time (ms)
50% 10
66% 13
75% 14
80% 15
90% 17
95% 17
98% 18
99% 18
100% 18 (longest request)</code></pre>
<b><br /></b><br />
<b>Summary</b><br />
With reverse proxy enabled, it's able to serve static images much faster.Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-78279009015961685862011-06-14T16:10:00.000-07:002011-08-09T17:36:33.854-07:00How to upgrade/install flash player for firefox in Linux (CentOS)In CentOS Linux, if you're browsing a site and firefox requires you to upgrade the flash player, here's a general procedure how it's done.<br />
<br />
<ol>
<li>Click the download or flash player button to redirect you to adobe's flash player download page.</li>
<li>Download the corresponding version, e.g 32 bit or 64 bit (usually saved by default on /tmp folder.</li>
<li>Close firefox for now.</li>
<li>From a console, go to the directory where you downloaded the flash player, named libflashplayer.so (/tmp in this sample).</li>
<li>From /tmp folder type <i>cp libflashplayer.so /home/jun/.mozilla/plugins</i> (where jun is your linux username)</li>
<li>Open firefox and your flash player should be working ok by now.</li>
</ol>
Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0tag:blogger.com,1999:blog-3192933619631828982.post-52108468445914620762011-06-13T19:06:00.000-07:002012-06-06T22:19:39.485-07:00MS Access VBA programmingMS ACCESS is a Rapid Application Development ms-office application, that is rarely used nowadays by programmers, obviously it's because it was designed for non-tech savy person to develop applications with no or minimal coding requirements.<br />
<br />
MS-ACCESS, if to be taken seriously as one programming tool, it could not just develop simple applications, it could also handle enterprise level SQL as backend database.<br />
<br />
<a name='more'></a><br />
So you wonder why majority of programmers doesn't use MS ACCESS instead. Most programmers tend to choose a particular programming based on the language popularity or work demands, it could have been directed upon from the IT director as a general standard tool of the web/software development department for good reasons.<br />
<br />
The real beauty of MS ACCESS is, you could develop real database applications requirements in less than a week, which usually could take 3 to 6 months compared to other programming languages.<br />
<br />
For instance, you could create one database application in just one file, and it contains all the underlying building blocks of the applications like Forms, Tables, Data/Grid views, SQL queries, and Reports, all of which could be done thru the wizard, or manually if you feel like tweaking or adding some customized codes.<br />
<br />
This is not my main programming language either, but for general back-office requirements, i've used MS ACCESS on small projects like Income Tax Calculator and Tax Report printing. I've also created a freelance project like Bus booking (reservation system), and Product Catalogue Management which has at least less than a million records, and done each in less than one week.Jack Cuervohttp://www.blogger.com/profile/04187814248467781632noreply@blogger.com0