Tuesday, December 17, 2013

Threading to JavaScript 1

JavaScript is a single-threaded environment. Simply if you wants run multiple scripts at the same time you cant achieve that requirement with JavaScript. Think about the scenario in a web site you wants to retrieve data through AJAX, needs to do manipulation in UI and DOM at the same time. But you can do this because of script execution happens within a single thread. So in currently what you do normally achieve this kind of goal. You use techniques like setTimeout(), setInterval(), XMLHttpRequest, and event handlers. But in HTML5 gives to you better option than these workarounds. That is Web Worker.

A web worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. perfect for keeping your UI refresh, performant, and responsive for users. There are two types of web workers, Dedicated Workers and Shared Workers. In this article discuss about Dedicated web worker.

Let's do small demo about web worker. Create HTML content like below with two buttons. Those two buttons bind with 'onClick' event.

Web worker demo

Create script like below with two onClick events. First of all check whether browser support web worker. After check Worker object create or not. If it not create new object. If the web worker file exists, the browser will spawn a new worker thread, which is downloaded asynchronously. The worker will not begin until the file has completely downloaded and executed. If file not exists returns an 404, the worker will fail silently. Communication between a work and its parent page is done using an event model and the postMessage() method.


Following script shows the content of doWebWorker.js file. In this javascript file capture message from main page send data back to main page. And also worker terminate operation contain in this separate script file.
var message;
that = this;
self.addEventListener('message', function (e) {  
 //basic demo
 message = e.data;
 that.sendMessage(message);
}, false);

function sendMessage(message)
{
 self.postMessage(message);
}

When click Start Worker button send message to the web worker and eventlistener of web worker catch it send back to the main page. When click Stop Worker button terminate web worker.



Tuesday, December 10, 2013

Caching in ASP.NET MVC : What, Why and How

What is Caching in ASP.NET MVC ?

Caching is process of storing frequently used information and within high speed memory.


Why do we need caching in ASP.NET MVC ?

Most of the times ASP.NET application requirements makes the scenario to get user and page data from the server in all most every request. Because of this kind of accessing data from server each time directly effect the application performance. To avoid this kind performance and latency issues we can use Caching mechanism.

How do we manage caching in ASP.NET MVC ?

Page Output Caching
- In this method browser cache HTTP GET request for predefined time period. When user request same URL again that call not going to server, instead of that it returns already cache page. Following code snippet show the way of doing it.

[OutputCache(Duration=60, VaryByParam="None", Location="ServerAndClient")] Public ActionResult Index() { return View("Index"); }

Duration defined the time period caching should happen. Setting by location says where we wants to do the caching. In this code it done by both of server and client. Because of that user who request this url from another browser also not send the request to the server. We can defined place to locate the cache. VaryByParam create the different version of cache based on the form or query string parameters. You can create cache profile in the web config and use it in with controller.

Donut and Donut Hole Caching
- Donut and Donut hole caching also belongs to the page caching mechanism. But these two methods not cache full page like in output cache. Donut cache is the server side methodology and it cache entire page other than pieces of dynamic content. Donut hole cache do the opposite of it cache selected sections of the page and not cache entire remaining part of the page.

Windows App Fabric Caching Service
- In web farm solution implementing the caching mechanism getting more complex because of each server share the information created in one sever. To solve this kind of scenario use windows app fabric caching service. ASP.NET is the cache client. Cache client can hold the cache in it local store and communicate with cache cluster. When request the data first look in the local store then it look for the cache cluster. If cache cluster not contain that information looking for then it has go to original information source and get it.  

Data Caching 
- In your business application most of the time request same data frequently. This process directly effect to the performance of the application. Data caching is the solution for this kind scenario. Data caching can apply to the layers between data access and business logic. In between these two layers can cache the frequently request data then each time no need to make database request. Data caching use ObjectCache  and MemoryCache objects for the implementation. 

Application Caching 
- In this method use Application Cache API (AppCache) in HTML5. This give access to the local browser cache. To use application cache needs to create application cache manifest, reference manifest and transfer manifest to the client. When application cache enabled browser fetch it only three cases,
a). When makes the any changes to the manifest
b). When clear the cache by user
c). When cache updated by programmatically


Wednesday, April 10, 2013

State Management : What, Why and How


In this article focus on state management in ASP.NET MVC.

What is state management ? 


State Management is the process followed by developers in web application development to maintain state and page information over multiple request for the same or different pages.


Why do we need to manage state ?

The main way of communicating with internet  HTTP. This HTTP protocol is stateless. It doesn't know anything about last request. Not having to remember user's last request web server can handle many concurrent users. ASP.NET MVC is designed with this stateless nature of HTTP. Because of this reason when we needs to remember user last request or user information we have to take the approach of state management.

 How do we manage state in ASP.NET MVC ?

Client - Side 

Cookies  - small set of information passed to there server in every HTTP request. According to the requirement can set the expiration time for the cookies.

Query String - information appended to the URL. For secure the information can use HTTPS.

Hidden fields - Store value in the form hidden field. this value can use to send sever and operation of the client side.

Server - Side

Cache - cache object available for the all class within the application. This cache object can access through any user or page in the application domain.


Session - Information stored in the server and unique for the each user. There are mainly two method of session management which are InProc and OutProc. InProc use the web server memory and it comes with by default in IIS. In distributed application needs to use OutProc method. There are two method in OutProc way which are State server and SQL server. To use these methods in distribute application have to made changes to web config.

Profile - Information stored based on user name in a database. The profile is part of Membership and Roles provider.

Monday, February 4, 2013

SEO tool kit

Recently in a project client asked to enhanced the web site search engines. To fulfil that requirement selected tool call SEO tool kit given by Microsoft. This tool give you capability to increase rank in search result and optimize the content for it. This is run under internet information service (IIS). You have to install it to the IIS.


Using this tool you can analyse a website or a web application, create sitemaps, and
create robot exclusion rules and a robots.txt file for a site, which tell search engines not to
index a certain page. Site analysis give you violations of your web content as shown in below.

Using this tool you can check more information about violations in page level as well.

Download from here

Friday, July 8, 2011

උගෙනිමු C

අද අපි පරිගණක තාක්ෂණයට සම්බන්ද බොහො දෙනෙක් අසා තිබෙන පරිගණක මෘදුකාOග භාෂාවක් වන C ගෑන අද ඉදලා ඉගෙන ගනිමු.ගොඩක් පරිගණක තාක්ෂණයට සම්බන්ද  දෙවල් වල මුලික භාෂාව වන්නේ මේ C. වින්ඩොවස් මෙහෙයුම් පද්ධති, ජාවා වෑනි බොහෝ නිපෑයුම් වල මුලික හරය වන්නේ මේ C තමා. මේ භාෂාව හදුන්වන්නේ structural  programming  language එකක් ලෙසට. ඒ ගෑන මම වෙන්ම ලිපියකින්  ඔබ වෙත එනම් මොනවද එ කියලා. හොදයි අද අපෙ පළමු පාඩමට යමු.
මේ සදහා මම භාවිතා කරන editor එක තමා notepad++ .
හොදයි එහෙනම් අපි පළමු වෑඩසටහන බලමු.
image
මෙසේ ලියු පරිගණක වෑඩසටහන මේ ව්දියට  hello.c ලෙස save කර ගන්න.
image
පළමු පේළිය : #include<stdio.h>
මේක තමා  input/output header file එක විදියට භාවිතා කරන්නෙ.
දෙවන පේළිය : main()
මේක තමා වෑඩසටහන ක්‍රියාත්මක විමට ඈතුලුවන තෑන. වෑඩසටහනේ body එක වෙන්නෙ මේක තමා.body එක {..}  වලින් සමන්විත වෙලා තියෙන්නෙ.
තෙවන පේළිය : printf(“Hello Welcome to the C Programming “);
මේකෙන් තමා quotes ඈතුලෙ තියෙන statements print   කරලා පෙන්නන්නෙ. මේ library function  එකට main() එකෙන් කාතා කරනවා.
හතරවන පෙළිය : }
main() function body  එක අවසන් කරන්නේ මේකෙන් තමා.
ඕන්න ඉතින් අදට පාඩම ඉවරයි. මේක බලලා try එකක් දිලා ඔයලාගේ අදහස් දෙන්න.තවත් පාඩමකින් හමු වෙන තුරු ඔබ සෑමට ජය. :)













Saturday, January 8, 2011

The Unforgettable Day

d Today is the 7th of January in 2011. I'm standing on Microsoft Student Champ monthly meeting in January. at the end of the session wela came front of the audience and  start to speak about the new Microsoft Student Ambassadors. why this day is  unforgettable day for me. today is the one of greatest day of my life because i selected as a new Microsoft Student Ambassador(MSA)  in representing OUSL. so this is great experience for me after i being a champ. so came through in this community in last one half year time when I'm looking back  i gain a lot of experience in various sectors such as communication skills, technical stuff and i met  lot of valuable  personal in the industry through the champ community. i adding more thing to this i got a great experience working with student of various universities and share knowledge with them was a such wonderful memories in my life.i have to write many more things as like this about this community.

Now on onwards I'm working with this community as Microsoft Student Ambassador(MSA). so its more responsible than earlier and must be give my full support and all my skills to build up the this community as such great and leading student community in this country in this year working with my fellow ambassador. so i request all the students from IT related field come and join with us and Connect! Share !  Grow! …….
[ Now’s  Your  Time to Shine. ]

Friday, November 19, 2010

Chicken Submarine

csubToday i thought write something on different topic. It’s about Chicken Submarine of Dinemore (Sri Lanaka).specialty of Dinomore because its make me crazy on  to submarine. when we were in schooling some of weekends we went to Dinomore at kollupitiya (but no big experience in submarine as i remembered ).
Before i go to the Dinomore i had some experience and taste about specially on chicken submarine in KFC. In the time ago KFC  submarine was pretty good on taste. before three or four months ago  i went to KFC with my friends and ordered  chicken submarine. what the hell !.. when had two three  bite it was a…really crap ! as well as it was not well enough to price of it…
Then what to do i changed the place where we go ……its changed to Dinomore. Because their now located at kohuwala. the very first day of Dinomore at kohuwala  we ordered Chicken Submarine…it’s make we crazy on Chicken Submarine….late their introduce Spicy Chicken Submarine actually it’s was Thundory Chicken. i was  taste it on my birthday…hmmm..yameee !
Actually Dinomore Submarines are sometimes can’t handle on to single person because its that much of large one. The taste of it pretty good and it satisfies the cost of it. The reason behind the this post is today i went to Dinomore at kohuwala with one of my best  friend. it was time around 12 or 12.30 p.m. we had a two Chicken Submarine..hmmm..god..it  was cover the our hungry and as well as our lunch.