Thursday, July 18, 2013

Typescript

objective : In this article we will try to understand the reason behind Usage of TypeScript and various Places it can be used.

TypeScript is Superset of Javascript. If you have installed TypeScript then you would see Typescript to be generating its Javascript file (img1)



In the image we can see app.ts file has its app.js file. App.js is referred in Default.htm file. There are no references needed to build typescript program.

Typescript almost acts as javascript editing tool. you can follow the below link to install TypeScript


If you download Typescript and extract files then you would see below list of folders.

                     ( Img 1 )                                                             ( Img 2 )

                                                                     ( Img 3 )
Lets see what this file contain.

1) Image 3 --* Microsoft.TypeScript.targets : This is a Schema file which include information about TypeScript Compiler.

Exec Command=$(ProgramFiles)\Microsoft SDKs\TypeScript\tsc.exe


2) Image 2 --* tsc.js is the command-line compiler used by tsc.exe. Both typescript.js and tsc.js are largely identical but tsc.js has the command-line options parser and batch compiler needed for the command-line compile. typescript.js is just the core compiler.

 These are few files which would give you glimpse about what is typescript and how Microsoft manages typescript. As it looks it is just tip of iceberg. I would encourage you to go through other files.

Going further we will work on some of the typescript concepts

For more Info click on URL http://solvemytechissue.blogspot.in/








Tuesday, January 15, 2013

C# Tuple storing various type of datatype

Note:in the last article we discussed about List, Today i am going to take you around Tuple which is part of C# generic,

Tuple in C# was introduced in 4.0

Article speak about.
1) What is C# Tuple.
2) Why C# Tuple? / Use of C# Tuple.
3)  Adding items in C# Tuple.
4) Find Items in C# Tuple / Using C# Tuple in List.

What is C# Tupple?

C# Tupple is a fixed size collection, capable of storing various type of datatype. Tuple Type is a class and stored in Managed Heap

Syntax
Tupple(datatype1value,datatype2value,......)

ex:


Lets take the above line and put it in a loop.

         

By doing so, a new tuple is created each time with i value in it.Tuple stores this information in item1, item2 and item3

One of the ways to obtain the information, you can simply type,
                                 
                                        int value = tp.Item1;



Why C# Tupple?

C# tuple provides you a platform to work with different types of return data type, If you see a below example below:



You would find it extremely hard or not possible to create such return datatypes in any other form of generics, But still Tuple has to be improved in many places its not as good as List or Dictonary. It still needs to have components search index and many.

 Adding Items in C#

One can use any of the way to store value in Tuple, Like the below examples.

OR


Tuple inside a Tuple 

Till now we had a tuple inside a loop but i am not happy with maximum 8 elements rule and i want to extend it.

Tuple can have n number of elements in it, but it has to be tuple inside a tuple



As we see in above example we can have n number of element insiode a tuple.

Tuple with List

You might have observed or wondering why i need to add this tuple in a loop where it will loose value on every time it enters a loop. Let's try something more
 
Now lets add the above loop in a list so that i can record all tuple values in List.




Post me/Please let me know if you have any query

To know about aspdotnet2share follow the below link

                            http://en.wikipedia.org/wiki/User:Sunilthespark/sandbox

For more Info click on URL http://solvemytechissue.blogspot.in/

Tuesday, January 8, 2013

C# List in properties to get tree type structure

Objective: Create a class which should contain List and that list should have its own properties to get tree type structure.

Recently i was asked to develop a property which should have a list in it and that list should have its own properties.

Before i start it, i expect you to have knowledge about List and properties in C#. if not then here you are.

What is a Property ?

Ref: http://msdn.microsoft.com/en-us/library/x9fsa0sw.aspx

A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors.


What is a List ?

Ref: http://www.c-sharpcorner.com/UploadFile/mahesh/list-in-C-Sharp/

The List(of T) class in .NET represents a strongly typed list of objects that can be accessed by index. List class is a collection and defined in the System.Collections.Generic namespace and hence provides most of the collections related built-in methods and properties including add, remove, search, and sort.  

Step 1) Lets take a class Demo and set a properties

public class Demo
{
             public string demo1{get;set;}           -----------------(1)
             public string demo2{get;set;}           -----------------(2)
              public List demo3 { get; set; } --------(3)
}

Description:  the (1) and (2) line i create a property called demo1 and demo2 and demo3 is a list which has its own field.

Step2) create a class called listdemo which we have mentioned it as datatype in step3
public class ListDemo
{
           public string demo3a{get;set}            ---------------(1)
           public string demo3b{get;set;}          ----------------(2)
}

step3) In the below code we add it to a list
 static void Main(string[] args)
        {
            ListDemo lstdmo = new ListDemo();
            lstdmo.demo3a = "i m demo3 first child";
            lstdmo.demo3b = "i m demo3 scnd child";
            Demo dm = new Demo();
            dm.demo1 = "i m demo1";
            dm.demo2 = "i m demo2";
            dm.demo3 = new List();
            dm.demo3.Add(lstdmo);
        }

on run add a breakpoint on flower bracket after  dm.demo3.Add(lstdmo); and check dm in "quick watch" and you find something like below image


This help a lot when you want to carry a object with parent-child relation like in treeview binding and many..


Post me/Please let me know if you have any query

For more Info click on URL http://solvemytechissue.blogspot.in/

Wednesday, January 2, 2013

Asp.net Session TImeout Dialog Javascript

Objective: Create Session Timeout Dialog.

Last week I showed, how we can create a session timeout Dialog Box on server side. You would find many timeout control but as i tried most of them don't work as our expectation, My group wanted this session out control dialog to popup after 60 minutes of Screen/Page Idle, in my last blog Asp.net Session Timeout we found that the page was sending request to server and on that basis the user would see the time left in the dialog.

This blog would put lime light on how we can create Asp.net Session Timeout Dialog from JavaScript.

Step 1) Add Timer with a interval mentioned in it, Interval="20000" is equal to 20 seconds.


Step 2) Add Dialog box, which is Session Timeout Dialog box, 

Session Timeout Dialog Box contains A span which would show time left for session Time out and a button which on clicked will Resume Session.



 Step 4) Write the below code in timer event.

protected void timer1_Tick(object sender, EventArgs e)
    {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Timeout", "javascript:timer2Tick();", true);
        timer1.Enabled = false;
    }

Has 20seconds of idle time reaches, the timer ticks and after Registering Timeout Function, the timer gets disabled.

Step 5) Write the below in Button click event

       protected void btn_click(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Timeout",                 "javascript:btnclick();", true);
        timer1.Enabled = true;
     }
Step 6) Write the below javascript function

 var ss = 60;
    var mm = 04;
    function timer2Tick() {
        document.getElementById("TimerDiv").style.visibility = "visible";
      
            ss -= 01;
            if (ss >= 00) {
                document.getElementById("timer").innerHTML = "0" + ss + " seconds";
                document.getElementById("timerss").innerHTML = "Session Will Logout  in " + "0" + mm + " Minutes ";
            }
            else {
                mm -= 01;
                if (mm >= 00) {
                    document.getElementById("timer").innerHTML = "0" + ss + " seconds";
                document.getElementById("timerss").innerHTML = "Session Will Logout  in " + "0" + mm + " Minutes ";
                    ss= 60;
                }
                if (ss <= 00 && mm <= 00) {

                    window.location = "Logout.aspx";
                    return;
                }
            }
            var counter2 = setTimeout("timer2Tick()", 1000);
            return;
        }

        function btnclick() {
            document.getElementById("TimerDiv").style.visibility = "hidden";
        }

The above java script function is the countdown timer which directs to logout.aspx .

Here is the below Session Timeout Window


 Note:1) Please increase session timeout in web.config at least 5minutes of sum of time given in timer1 interval and session["CountDownTimer"].
2)Increase Application pool which is in IIS manager i.e Application Pool> Advanced Settings> Idle Timeout greater than Web config session timeout.



Post me/Please let me know if you have any query

For more Info click on URL http://solvemytechissue.blogspot.in/

Thursday, December 27, 2012

Asp.net Session Time Out Dialog

Session Time out is always been so important that many end up with Failure, the available tools like Timeout.js control fail in many circumstances.

Session Time out what i have created, prompts user after given time and the countdown starts as it becomes 00:00:00 it redirects to another page, if user likes to continue the session then he needs to click on button available in the Session Time Out dialog and session continues for that set of time.

So i just thought to do some work around for Session Time Out dialog using Timer control of asp.net and here you are.
Steps to Create Server Side Session Time Out dialog
Step 1) Take Two Timer Like Below one

As we have properties in Windows Timer we do need to set Timer Properties here too, like 20000 is approx 20 seconds, Let Timer2 be disabled.
Step 2)Create a Session Time Out dialog box which should turn the entire page disabled and timer should be shown, to do that you need to work on style using Div, something like below 



The above Code of line would create a Session Time Out dialog box when ever TimerDiv is called.

Note: Please be more creative on Session Time Out dialog box as what i have coded is bit rough

Step 3) Create Class file for CountDown, I have just used it from another site

public class CountDownTimer
{
    public TimeSpan TimeLeft;
    System.Threading.Thread thread;
    public CountDownTimer(TimeSpan original)
    {
        this.TimeLeft = original;
    }
    public void Start()
    {
        // Start a background thread to count down time
        thread = new System.Threading.Thread(() =>
        {
            while (true)
            {
                System.Threading.Thread.Sleep(1000);
                TimeLeft = TimeLeft.Subtract(TimeSpan.Parse("00:00:01"));
            }
        });
        thread.Start();
    }

}




Step4) on page load paste the below line of code and see to it that u are using some sought of State management, here i am using session, There are some scenarios where developer may want to add this in master page which would contain menu that would redirect new content page at that time we need to reset it. you see me using (Request.Form.AllKeys).Length which would be zero normally or you do need to find some alternative way.



if (Session["CountdownTimer"] == null || (Request.Form.AllKeys).Length == 0)
        {
        Session["CountdownTimer"] = new CountDownTimer(TimeSpan.Parse("00:01:20"));
        (Session["CountdownTimer"] as CountDownTimer).Start();
        }




Step5) And here comes the last and very important part of this control and here is the below code
protected void timer1_Tick(object sender, EventArgs e)
    {      
        //Enable Second Timer
        Timer2.Enabled = true;
        timer1.Enabled = false;
    }
    protected void timer2_Tick(object sender, EventArgs e)
    {
       if (TimerDiv.Visible != true)
        {
            TimerDiv.Visible = true;  
        }
        if (Session["CountdownTimer"] != null)
        {
            txtclock.Text = (Session["CountdownTimer"] as CountDownTimer).TimeLeft.ToString();
        }
        if (txtclock.Text == "00:00:00")
        {
            Response.Redirect("About.aspx");
        }      
    }
    protected void btn_click(object sender, EventArgs e)
    {
        TimerDiv.Visible = false;
        timer1.Enabled = true;
        Timer2.Enabled = false;
        Session["CountdownTimer"] = new CountDownTimer(TimeSpan.Parse("00:01:20"));
        (Session["CountdownTimer"] as CountDownTimer).Start();
    }




In timer1_tick you would see timer1 gets disabled which would happen in 20seconds now as we have set its interval to 20000, after 20sec the timer1 get disabled and timer2 gets enabled which would push the dialog box and the work begins , the btn_click is the point where the user would find to the application.



Note:1) Please increase session timeout in web.config at least 5minutes of sum of time given in timer1 interval and session["CountDownTimer"].
2)Increase Application pool which is in IIS manager i.e Application Pool> Advanced Settings> Idle Timeout greater than Web config session timeout.



Post me/Please let me know if you have any query

My next Task is to create Session Time Out dialog through Javascript, so that i can avoid post-back, for now it works fine for me, see you soon.

For more Info click on URL http://solvemytechissue.blogspot.in/