Skip to main content

Posts

Showing posts from 2012

Sliding and Absolute expiration in Caching

Caching Mechanism and Its Expirations ASP.net cache or AppFabric Caching are ways to  increase the performance of the web application by r educing server round trips to database. However the validity of the cached data needs to be ensured, to enforce this, we have the following options 1. Dependency Mechanisms:      Files, SQL Cache Dependency etc This ensures that the cache is re-validated or refreshed once a dependent has changed or been altered 2.  Expire Cache:      The cache will expire after a time frame and the newer items will be added to cache when ever accessed or processed after expiry.  In Cache Expiry, we have the following options 1. Absolute Expiration:   Absolute expiration means It will expire cache after some time period set at the time of activating cache. This will be absolute expiration whether cache will be used or not It will expire the cache. This type of expiration used to  cache data which are not frequently changing. 2. Sliding Expiration: 

Constructors for user defined Exceptions in C#

The following are the rules that are to be adhered to when creating any custom user  defined exception. 1. Follow the Naming convention so that the self-explanatory name of the exception ends with Exception like: ArgumentNullException. 2. The following constructors should be defined public NewException() public NewException(string message) public NewException(string message, Exception exception) protected or private NewException(SerializationInfo serializationInfo, StreamingContext streamingContext) These ensure that the created Exception satisfies the default rules of User Defined Exceptions. [Also Satisfies FxCop Validation] -- Saravanan

Handling Enumerations in C# as Strings

In Order for an Enumeration in C# to be processed as a string, use the string formats described below, Sample: enum Colors {Red, Green, Blue, Yellow = 12}; Colors myColor = Colors.Yellow; myColor.ToString("g") = Yellow myColor.ToString("G") = Yellow myColor.ToString("x") = 0000000C myColor.ToString("X") = 0000000C myColor.ToString("d") = 12 myColor.ToString("D") = 12 myColor.ToString("f") = Yellow myColor.ToString("F") = Yellow As shown in the above samples, the following format specifiers :   g,G,x,X,d,D,f and F are used to convert a integer based enum value to string format. -- Saravanan

Dynamically adding HTML DOM elements Via jQuery

How to Add DOM Elements Via jQuery The following script and fiddle demonstrate how to add the DOM elements via the jQuery library ​ $(document).ready(function() { var el = $(" ").attr({ "type": "checkbox", "class": "select", "value": "hi" }); var lbl = $(" ").text("hi"); $(".op").append(el); $(".op").append(lbl); console.log(el); });​ To play around, the fiddle is here -- Saravanan

Comparing Strings in C#.Net

In order to compare strings for their equivalence, we have to follow this Rule from Microsoft " When you specify either  StringComparison.Ordinal  or  StringComparison.OrdinalIgnoreCase , the string comparison will be nonlinguistic. That is, the features that are specific to the natural language are ignored when comparison decisions are made. This means the decisions are based on simple byte comparisons and ignore casing or equivalence tables that are parameterized by culture." -- Saravanan

Windows AppFabric FAQ's

Exception Solution An existing connection was forcibly closed by the remote host if you're IIS applicatin is running under and Application Pool that uses the identity of DOMAINNAME\domainuser, you would add this to the allowed client account list with the following command: Grant-CacheAllowedClientAccount DOMAINNAME\domainuser. [OR] use this Grant-CacheAllowedClientAccount everyone [OR] Set-CacheClusterSecurity -ProtectionLevel None -SecurityMode None Cache Configuration with Windows PowerShell Reference Cache Administration with Windows PowerShell Reference -- Saravanan

Windows AppFabric Caching

Windows AppFabric Caching Here is a collection of links that are useful for kickstarting the use of Windows AppFabric Caching, formerly known as Velocity Caching from Microsoft. Tutorials Concepts and Architecture Physical Architecture Diagram Logical Architecture Diagram AppFabric Caching Concepts Caching Admin in Windows PowerShell -- Saravanan

Migrating from ASP.Net MVC2 to MVC3

In order to migrate an existing ASP.NET MVC2 Application to ASP.NET MVC3 application, we have to follow the steps described here so that we can consume the Razor views inside the migrated application along with the latest jQuery features and the Mordenizer and also can switch to Entity Framework4. The upgrade process is described here This task was just a cake. Nice details and procedure from Microsoft. -- Saravanan

jQuery Tips

to select the first option in a select using jquery: $("#target option:first").attr('selected','selected'); to get the value of the first option tag in a select using jquery $("#target").val($("#target option:first").val()); to remove the "selected" from any options that might already be selected $('#target option[selected="selected"]').each( function() { $(this).removeAttr('selected'); } ); -- Saravanan

iTextSharp Documentation and Guides

Useful Resource Links for iTextSharp Pdf Library for .Net Framework. The following links are found to have useful references while consuming the iTextSharp Pdf library. Google Search Results Documentation from AfterLogic 4GuysFromRolla StackOverFlow Solutions StackOverFlow Solutions C# Samples Mikes Dotnet blog -- Saravanan

Using Firefox without Caching of network contents

This is the detail that i found regarding the disabling of FireFox Cache so that any network resource that is needed will be fetched from the server and then displayed to the user The steps are : 1. Fire up FireFox 2. Type about:config in your address bar 3. Type ‘cache’ in the search bar, and look for network.http.use-cache, and double click it to set it to false. Double clicking it again will set it to true and re-enable the cache Original article was here -- Saravanan

SFTP and File Upload in SFTP using C# and Tamir. SShSharp

The right choice of SFTP Server for Windows OS Follow the following steps, 1. Download the server version from here . The application is here 2. Provide the Username, password and root path, i.e. the ftp destination. 3. The screen shot is given below for reference. 4. Now download the CoreFTP client from this link 5. The client settings will be as in this screen shot: 6. Now the code to upload files via SFTP will be as follows. //ip of the local machine and the username and password along with the file to be uploaded via SFTP. FileUploadUsingSftp("172.24.120.87", "ftpserveruser", "123456", @"D:\", @"Web.config"); private static void FileUploadUsingSftp(string FtpAddress, string FtpUserName, string FtpPassword, string FilePath, string FileName) { Sftp sftp = null; try { // Create instance for Sftp to upload given files using given credentials sf

using the Id property in JSON objects

When using the `Id` as a property in the Javascript Objects, and sending them using JSON.stringify, they are not model bound as `Id`, instead, they are skipped and inserted as null in the bound model in the controller. Hence, Never Use `Id` as a property for a JSON object.

Credits Deducted for Any Reply to Dirty Dozen Topic

We would like to charge credits for ANY reply to a Dirty Dozen topic regardless of whether an avatar is used or not.  We would like to charge two (2) credits per reply, but if they would like an avatar it will still cost them an additional four (4) credits. to indicate the user that he has insufficient credits to make a post, we use the following code in the file : /home/webmaster/public_html/mod/groups/actions/forums/addpost.php [code] /* ds start - 11.02.2010 -> to check for the user credits */ $avid = intval(get_input('cavid')); $user = get_loggedin_user(); if($user["credits"] < $avCost) {     register_error(elgg_echo("You have insufficient Credits to make a post. Please purchase Credits"),"errors");     forward("http://dirtdisser.com/mod/cubet_membership/upgradecredits.php"); } else if($user["credits"] > $avCost) {     if($avid > 0)     {         $avCost = $avCost * 6;     }     else     {

admin manageable Front Page Message

On the frontpage there is a chat box with text in it (divider id #frontpage-message).  We would like to make this dynamic so any admin can change that text on a page in the Administration section.  Please be sure to limit the amount of characters a user can input so it does not allow enough text to overflow from the chatbox. to write the page title and set the url [code] else if($type=='CHM') {     $external_page_title = elgg_echo('expages:CHM'); } [/code] code to generate the form for handling the messages [code] /* ds start - CHM */ if($type=="CHM") {     $msg = "Edit the Frontpage welcome Message here. <br /><br />";         $chatMessageForm = <<<EOT         <form method="post" action="">             <label for="chatMsg">                 Customize the Front Page Chat Message Here. [Max : 50 characters]             </label>             <textarea id="

hide the reply option for all the commented wireposts in the "thewire posts"

This option is implemented by checking whether the comment text has a @ and if so, we just indent it and hide the reply link from the user so that this comment cannot be commented. /home/webmaster/public_html/mod/thewire/views/default/object/thewire.php 1. check for the @ in the text [code]     $haystack= $vars['entity']->description;     $needle = "@";     if($haystack[0] == $needle)         $shallIndent = TRUE;     else         $shallIndent = FALSE; [/code] 2. use the indentation for the div which is a comment or a reply to a post made earlier. [code]  if($shallIndent)     {         ?> <!-- style="margin-left:50px"--> <div class="thewire-singlepage"  style="margin-left:50px"> <?php } else { ?> <div class="thewire-singlepage">     <?php } ?> [/code] 3. code to display the link only when the user is logged in and when this post is not indented. [code] <

creating a facebook messaging system using php and facebook access tokens

Here is the procedure that was used to write posts in facebook by allowing the user to signin using their facebook id and then writing a post in their facebook profile page. 1. use the following url with your own application id created in facebook facebook login     Then after the page is reloading, get the access token returned by facebook for the logged in user     3. use the following lines of code to get the facebook access token from the set cookie above and use it to send the post data via curl to facebook if(isset($_COOKIE['access_token_fb'])) {     /* NEVER DELETE THIS LINE. THIS IS THE MOST IMPORTANT LINE IN USING FACEBOOK */     json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' .$_COOKIE['access_token_fb']));         /* new testing code */         $url = "https://graph.facebook.com/me/feed";     $ch = curl_init();     $attachment =  array(   'access_token'  => $_COOKIE['access

HTML to C# Color Conversion

To convert a System.Drawing.Color to the HTML color format (Hex value or HTML color name value) and back. System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#F5F7F8"); String strHtmlColor = System.Drawing.ColorTranslator.ToHtml(c);

Client Script for GUID Generator

To create GUID's or Pseudo-Random numbers in Javascript, use the following function guidGenerator() { var S4 = function() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); }; return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()); } This was adapted from the Original Work